简体   繁体   English

python 中的 concat 和 append 形状错误

[英]wrong shape with concat and append in python

I have two datasets df1 with shape (4045, 188) and df2 with shape (10505, 188)我有两个形状为(4045, 188)的数据集df1和形状为(10505, 188)df2

df1 = pd.read_csv('ptbdb_normal.csv')
df2 = pd.read_csv('ptbdb_abnormal.csv')

To concat them i use:为了连接它们,我使用:

frames = [df1,df2]
df_con = pd.concat(frames)

or或者

data_appended =df1.append(df2)

However this approach returns me Dataframe with shape (14550,309)然而,这种方法返回给我 Dataframe 形状(14550,309)
What I need is new dataset with shape (14750,188)我需要的是具有形状的新数据集(14750,188)

Where am I making mistake?我在哪里犯错?
I took it from pandas docs, and SO thread here ( merging two datasets with same index)我从 pandas 文档和这里的 SO 线程中获取它(合并具有相同索引的两个数据集)

My problem is exactly the same as the one ilustrated here:我的问题与此处说明的问题完全相同:

https://datascience.stackexchange.com/questions/10783/how-do-i-merge-two-data-frames-in-python-pandas https://datascience.stackexchange.com/questions/10783/how-do-i-merge-two-data-frames-in-python-pandas

在此处输入图像描述

df1.columns=df2.columns.values
data_appended =df1.append(df2)

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

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