将列追加到pandas数据框 [英] Append column to pandas dataframe
本文介绍了将列追加到pandas数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能很容易,但是我有以下数据:
This is probably easy, but I have the following data:
在数据帧1中:
index dat1
0 9
1 5
在数据帧2中:
index dat2
0 7
1 6
我想要一个具有以下形式的数据框:
I want a data frame with the following form:
index dat1 dat2
0 9 7
1 5 6
我尝试使用append
方法,但是得到了交叉连接(即笛卡尔积).
I've tried using the append
method, but I get a cross join (i.e. cartesian product).
什么是正确的方法?
推荐答案
一般来说,您只是在寻找联接:
It seems in general you're just looking for a join:
> dat1 = pd.DataFrame({'dat1': [9,5]})
> dat2 = pd.DataFrame({'dat2': [7,6]})
> dat1.join(dat2)
dat1 dat2
0 9 7
1 5 6
这篇关于将列追加到pandas数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文