Skip to content
Advertisement

Tag: pandas

Add Categorical Column with Specific Count

I’m trying to create a new categorical column of countries with specific percentage values. Take the following dataset, for instance: I’m trying the following script to get the new column: However, I’m getting all the countries with equal count. I want specific count for each country: Desired Output What would be the ideal way of getting the desired output? Any

Remove part of a string from pd.to_datetime() unconverted values

I tried to convert a column of dates to datetime using pd.to_datetime(df, format=’%Y-%m-%d_%H-%M-%S’) but I received the error ValueError: unconverted data remains: .1 I ran: to identify the problem. 119/1037808 dates in the date column have an extra “.1” at the end of them. Other than the “.1”, the dates are fine. How can I remove the “.1” from the

Chain df.str.split() in pandas dataframe

Edit: 2022NOV21 How do we chain df.col.str.split() since this returns the split columns if expand = True I am trying to split a column after performing .melt(). If I use assign I end up using the original column and the melted column actually does not even exist. Answer Using expand converts it into a DataFrame, which you do not really

Advertisement