问题
I have a long format dataframe like the following:
In reality, my dataframe is about 10k rows and there are about 400 possible values of category. I'd like to melt my dataframe into a wide format like the following:
I can think of a couple ways to do this, but what would be an efficient way to do this transformation?
回答1:
Check with crosstab
out = pd.crosstab(df['Obs'], df['Category'])
回答2:
Isn't this crosstab:
pd.crosstab(df['Obs'], df['Category'])
来源:https://stackoverflow.com/questions/64419988/most-efficient-way-to-melt-dataframe-with-a-ton-of-possible-values-pandas