0
我有这样的国家的名单:通过字符串调用数据帧
country = ["Brazil", "Chile", "Colombia", "Mexico", "Panama", "Peru", "Venezuela"]
我创建使用的名字从国家列表中的数据帧:
for c in country:
c = pd.read_excel(str(c + ".xls"), skiprows = 1)
c = pd.to_datetime(c.Date, infer_datetime_format=True)
c = c[["Date", "spreads"]]
现在我想成为能够使用列日期作为关键字合并所有国家的数据框架。我们的想法是创建类似下面的循环:
df = Brazil #this is the first dataframe, which also corresponds to the first element of the list country.
for i in range(len(country)-1):
df = df.merge(country[i+1], on = "Date", how = "inner")
df.set_index("Date", inplace=True)
我得到了错误ValueError: can not merge DataFrame with instance of type <class 'str'>
。看来python没有调用名字在国家列表中的数据框。我怎样才能从国家名单中调用这些数据框?
谢谢师父!
感谢您的见解。我明白了,但不知何故,我无法看到merged_df。 – Guga