Skip to content

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: Desire…

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 DataFra…