【发布时间】:2021-01-29 02:40:03
【问题描述】:
我想用循环创建多个 df
这是我的代码:
index_investing= {"S&P 500","Nasdaq 100"}
对于 index_investing 中的 names_index:
df_names_index=investpy.get_index_historical_data(index=names_index, country='United States', from_date='01/01/2005', to_date= '31/12/2020')
代码返回df_names_index,即df_Nasdaq 100
如何创建循环:
df_S&P 500 和 df_Nasdaq 100
【问题讨论】:
-
动态创建变量名通常是个坏主意。更好地创建以索引为键、数据帧为值的字典。
-
你能解释一下吗?
-
在循环之前创建一个字典,并在循环的每次迭代中添加一个新条目。
-
我该怎么做对不起我的新手
-
那么你应该先通过Python tutorial如果还没有完成。