简体   繁体   English

用大量可能的值熊猫来融化数据框的最有效方法

[英]Most efficient way to melt dataframe with a ton of possible values pandas

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.实际上,我的数据框大约有 10k 行,大约有 400 个可能的类别值。 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?我可以想到几种方法来做到这一点,但是进行这种转换的有效方法是什么?

这不是交叉表吗:

pd.crosstab(df['Obs'], df['Category'])

crosstab检查

 out = pd.crosstab(df['Obs'], df['Category'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Pandas DataFrame 中转换列值的最有效方法 - Most efficient way to convert values of column in Pandas DataFrame 给定值列表迭代过滤 Pandas dataframe 的最有效方法 - Most Efficient Way to iteratively filter a Pandas dataframe given a list of values 在 pandas dataframe 中计算不同值的最有效方法是什么? - What is the most efficient way to get count of distinct values in a pandas dataframe? 在 pandas 中计算平方 dataframe 的最有效方法 - Most efficient way to compute a square dataframe in pandas pandas DataFrame 中映射列的最有效方法 - Most efficient way of mapping column in pandas DataFrame 以最有效的方式将字典嵌套到 Dataframe - Nested dictionary to Dataframe in the most efficient way possible 大熊猫数据框与字符串值融为一体 - pandas dataframe melt with string values 如何通过python / pandas中另一个数据框的值来标记一个数据框的列的最有效方式? - How to flag the most efficient way a column of a dataframe by values of another dataframe's in python/pandas? 操作 pandas dataframe 值的有效方法 - Efficient way to manipulate values of a pandas dataframe 检查 Pandas 数据框中列中的多个条件的最有效方法是什么? - What is the most efficient way to check several conditions in columns in a pandas dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM