如何组合两个数据框? [英] How do I combine two dataframes?
本文介绍了如何组合两个数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Pandas 数据框.我有一个初始数据框,比如 D
.我像这样从中提取两个数据帧:
I'm using Pandas data frames. I have a initial data frame, say D
. I extract two data frames from it like this:
A = D[D.label == k]
B = D[D.label != k]
我想将 A
和 B
结合起来,这样我就可以将它们作为一个 DataFrame,类似于联合操作.数据的顺序并不重要.但是,当我们从 D
中采样 A
和 B
时,它们保留了来自 D
的索引.
I want to combine A
and B
so I can have them as one DataFrame, something like a union operation. The order of the data is not important. However, when we sample A
and B
from D
, they retain their indexes from D
.
推荐答案
我相信你可以使用append
方法
bigdata = data1.append(data2, ignore_index=True)
为了保持索引,不要使用 ignore_index
关键字...
to keep their indexes just dont use the ignore_index
keyword ...
这篇关于如何组合两个数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文