我有2 DataFrames
我想要合并。我查看了文档,并试图执行以下操作,但对如何执行操作感到困惑。就像我说我有2个DataFrames
:合并两个数据帧
df1:
id name type currency
0 BTA.S Applewood Hard GBp
1 VOD.S Softwood Soft GBp
和
df2:
id
BTA.S 301.221525
VOD.S 213.791400
,我想回:
id name type currency price
0 BTA.S Applewood Hard GBp 301.221525
1 VOD.S Softwood Soft GBp 213.791400
凡从DF2价格列合并DF1。 (只是为了让你知道,我完成时会有更多的木材类型)。
我试图这样做的几种方法:
Result = df1.merge(df2[['*.S']], left_on='id', right_index=True)
在那里我遇到了异常:
ValueError: can not merge DataFrame with instance of type <class 'pandas.core.series.Series'>
和
Result = pd.concat([Df1, Df2], axis=1, ignore_index=True)
在那里我得到异常:
ValueError: labels ['type'] not contained in axis
但我感到困惑。对不起,如果这是一个基本的问题。任何帮助将非常感激。非常感谢