pandas 创建数据框字典
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35709402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create a dictionary of dataframes
提问by Milhouse
I've created a loop that produces a dataframe using input from a dictionary. I'd like to insert the ending dataframe into a new dictionary, name it the group number (12345), then start the loop over adding the new dataframe into the same dictionary, only it would have the new groups name (54321):
我创建了一个循环,它使用字典中的输入生成数据帧。我想将结束的数据帧插入到一个新字典中,将其命名为组号(12345),然后开始循环将新数据帧添加到同一个字典中,只有它会有新的组名(54321):
frames = {}
groups = ['12345', '54321']
for x in groups:
# Runs a bunch of calculations with the ending output being a pandas df
frames = df.to_dict()
Obviously I know this is wrong, I'm just scratching my head as to where I should go from here.
显然我知道这是错误的,我只是在摸索我应该从哪里开始。
回答by Sam
frames = {}
groups = ['123', '456']
for grp in groups:
#do some calcs to get a dataframe called 'df'
frames[grp] = df