循环创建多个数据框 [英] Create multiple dataframes in loop
本文介绍了循环创建多个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表,每个条目都是公司名称
I have a list, with each entry being a company name
companies = ['AA', 'AAPL', 'BA', ....., 'YHOO']
我想为列表中的每个条目创建一个新的数据框.
I want to create a new dataframe for each entry in the list.
类似
(伪代码)
for c in companies:
c = pd.DataFrame()
我正在寻找一种方法来执行此操作,但找不到它.有任何想法吗?
I have searched for a way to do this but can't find it. Any ideas?
推荐答案
您可以执行此操作(尽管显然如果要使用面向公众的代码,请非常谨慎地使用exec
)
You can do this (although obviously use exec
with extreme caution if this is going to be public-facing code)
for c in companies:
exec('{} = pd.DataFrame()'.format(c))
这篇关于循环创建多个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文