我尝试使用其日期作为索引来加入从一个pandas dataframe
到另一个列的列。但是我的代码产生TypeError
。请有人解释为什么会出现这个错误以及我可以做些什么来修复它?
提前致谢。
"""Balsjo THg, MeHg, TOC | Q and flux data 2005-2010"""
path2 = 'C:\\Users\\Google Drive\\SLU\\Thesis\\Data\\BalsjSite4.xls'
df2 = pd.io.excel.read_excel(path2, 'THg', header=0, parse_dates=[1], dayfirst=True, index_col='Date')
df3 = pd.io.excel.read_excel(path2, 'MeHg', header=0, parse_dates=[1], dayfirst=True, index_col='Date')
df4 = pd.io.excel.read_excel(path2, 'TOC', header=0, parse_dates=[1], dayfirst=True, index_col='Date')
print list(df2.columns.values)
print list(df3.columns.values)
print list(df4.columns.values)
cln_df2 = df2[['Q (mm/d)', 'THg (ng/L)', 'Flux']]
cln_df22 = cln_df2.append[df3[['MeHg (ng/L)']]]
print cln_df22.head()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-4f468a92d5ce> in <module>()
9 print list(df4.columns.values)
10 cln_df2 = df2[['Q (mm/d)', 'THg (ng/L)', 'Flux']]
---> 11 cln_df22 = cln_df2.append[df3[['MeHg (ng/L)']]]
12 print cln_df22.head()
TypeError: 'instancemethod' object has no attribute '__getitem__'
[u'Q (mm/d)', u'THg (ng/L)', u'RIM THg', u'Flux', u'Rim Flux', u'Error', 'Unnamed: 7', 'Unnamed: 8', 'Unnamed: 9', 'Unnamed: 10', 'Unnamed: 11', 'Unnamed: 12', 'Unnamed: 13', 'Unnamed: 14', 'Unnamed: 15', u'z', u'ae(bz)', u'c0e(fz)']
[u'Q (mm/d)', u'MeHg (ng/L)', u'RIM MeHg', u'Flux', u'Rim Flux', u'Error', 'Unnamed: 7', 'Unnamed: 8', 'Unnamed: 9', 'Unnamed: 10', 'Unnamed: 11', 'Unnamed: 12', 'Unnamed: 13', 'Unnamed: 14', 'Unnamed: 15', u'z', u'ae(bz)', u'c0e(fz)']
[u'Q (mm/d)', u'TOC (mg/l)', u'RIM TOC', u'Flux', u'Rim Flux', u'Error', 'Unnamed: 7', 'Unnamed: 8', 'Unnamed: 9', 'Unnamed: 10', 'Unnamed: 11', 'Unnamed: 12', 'Unnamed: 13', 'Unnamed: 14', 'Unnamed: 15', u'z', u'ae(bz)', u'c0e(fz)']
答案 0 :(得分:0)
我认为你应该这样做:
cln_df22 = cln_df2.append(df3[['MeHg (ng/L)']])
^ ^
you need to use brackets/parentheses instead of square brackets