简体   繁体   English

按行追加Pandas数据框

[英]Appending Pandas dataframes row-wise

I have checked append and it should be doing the job, but for some reason I cannot figure out the row-wise append isn't working. 我已经检查了追加 ,它应该可以完成工作,但是由于某种原因,我无法确定逐行追加是否起作用。

I have two dataframes with size (x,y). 我有两个尺寸为(x,y)的数据框。 I want to combine these two row-wise, so the final dataframe is of size (2x,y). 我想将这两个行逐行组合,因此最终数据帧的大小为(2x,y)。

I have tried to do the following: 我尝试执行以下操作:

frame_combined = frame_1.append(frame_2, ignore_header=True)
frame_combined = pd.concat([frame_1, frame_2], axis=1) # also axis=0

Edit: Doing these gives me a (2x,2y) dataframe. 编辑:这样做给了我(2x,2y)数据帧。 And also my dataframe has no header. 而且我的数据框没有标题。

What am I missing that I get a dataframe that is appended both row and column-wise? 我错过了将行和列都附加到一个数据框的缺失? And how can I do a simple row-wise append? 以及如何进行简单的逐行追加?

Thank you. 谢谢。

There's a problem with your frame_2 headers being different from frame_1 , this causes a misalignment, and if you're concatenating vertically, then your only option is to assign one to the other. 有您的问题frame_2头不同于frame_1 ,这会导致失准,如果你垂直串联,那么你唯一的选择就是指定一个到另一个。

So do so, 这样吧

frame_2.columns = frame_1.columns

Now concatenate: 现在串联:

frame_combined = pd.concat([frame_1, frame_2], ignore_index=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM