我有两个数据帧:
import pandas
import numpy
entry1= pandas.datetime(2014,6,1)
entry2= pandas.datetime(2014,6,2)
df1=pandas.DataFrame(numpy.array([[1,1],[2,2],[3,3]]), columns=['eins','zwei'], index=[entry1, entry1, entry2])
df2=pandas.DataFrame(numpy.array([[2,3],[3,3]]), columns=['eins','zwei'], index=[entry1, entry2])
我希望在df1中插入一个新列,在df2中查找相应的索引值并插入列的值' eins'与df1的新列具有与df1相同的索引值。结果应该如下所示:
df1['new column']=[2,2,3]
如何进行这种填充?
答案 0 :(得分:2)
>>> df1.join(df2['eins'], rsuffix='_new')
eins zwei eins_new
2014-06-01 1 1 2
2014-06-01 2 2 2
2014-06-02 3 3 3