Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将数据帧列添加到另一个数据帧_Python_Pandas - Fatal编程技术网

Python 将数据帧列添加到另一个数据帧

Python 将数据帧列添加到另一个数据帧,python,pandas,Python,Pandas,我有以下两个数据帧: df1: df2: 我正在尝试根据符号组合这两个数据帧,即:Target1/Target2必须作为新列添加: Symbol, Open, High, Low, Close, Target1, Target2 abc, 123, 676, 100, 343, 654, 565 我尝试了一些加入/合并的想法,但似乎无法使其发挥作用 请有人提供建议。只需concat他们并传递参数axis=1: In [7]: pd.concat([df,df1], ax

我有以下两个数据帧:

df1:

df2:

我正在尝试根据符号组合这两个数据帧,即:Target1/Target2必须作为新列添加:

Symbol, Open, High, Low, Close, Target1, Target2
abc,    123,  676,  100, 343,   654,     565
我尝试了一些加入/合并的想法,但似乎无法使其发挥作用


请有人提供建议。

只需
concat
他们并传递参数
axis=1

In [7]:

pd.concat([df,df1], axis=1)
Out[7]:
  Symbol  Open  High  Low  Close Symbol  Target1  Target2
0    abc   123   676  100    343    abc      654      565
或在“符号”列上:

In [8]:

df.merge(df1, on='Symbol')
Out[8]:
  Symbol  Open  High  Low  Close  Target1  Target2
0    abc   123   676  100    343      654      565
In [7]:

pd.concat([df,df1], axis=1)
Out[7]:
  Symbol  Open  High  Low  Close Symbol  Target1  Target2
0    abc   123   676  100    343    abc      654      565
In [8]:

df.merge(df1, on='Symbol')
Out[8]:
  Symbol  Open  High  Low  Close  Target1  Target2
0    abc   123   676  100    343      654      565