根据给定的列值创建多个DataFrame [英] Create multiple DataFrames based on given column values
本文介绍了根据给定的列值创建多个DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能有一个简单的解决方案,我只是找不到... 有了给定的DataFrame,我如何将其分成多个DataFrame并脱离类似的内容:
There's probably a simple solution to this that I just couldn't find... With the given DataFrame, how can I separate it into multiple DataFrames and go from something like:
>>>import pandas as pd
>>>d ={'LOT': [102,104,162,102,104,102],'VAL': [22,424,65,4,34,6]}
>>>df = pd.DataFrame(data=d)
>>>df
LOT VAL
0 102 22
1 104 424
2 162 65
3 102 4
4 104 34
5 102 6
收件人:
>>>df[0]
LOT VAL
0 102 22
1 102 4
2 102 6
>>>df[1]
LOT VAL
0 104 424
1 104 34
>>>df[2]
LOT VAL
0 162 65
具有3个不同的DataFrame 如果您需要更多信息,请告诉我.
With 3 distinct DataFrames Please let me know if you need more information.
推荐答案
这是一个简单的分组依据.让我看看我是否发现了骗子:
This is a simple groupby. Let me see if I find a dupe:
import pandas as pd
df = pd.DataFrame({
'LOT': [102,104,162,102,104,102],
'VAL': [22,424,65,4,34,6]
})
df = [x for _, x in df.groupby('LOT')]
好,我找到了东西.但是答案似乎太复杂了,所以我要把这个留在这里. 看起来很像:基于groupby的拆分熊猫数据框
Ok, I found something. However the answer seems overcomplicated so I'm gonna leave this here. Looks a lot like: Split pandas dataframe based on groupby
这篇关于根据给定的列值创建多个DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文