简体   繁体   English

通过追加不同大小的列将多个csv文件读取到大熊猫数据框中

[英]reading multiple csv file into a big pandas data frame by appending the columns of different size

so i am creating some data frame in a loop and save them as a csv file. 所以我在循环中创建一些数据帧,并将它们另存为csv文件。 The data frame have the same columns but different length. 数据帧具有相同的列,但长度不同。 i would like to be able to concatenate these data frames into a single data frame that has all the columns something like 我希望能够将这些数据帧连接到具有所有列的单个数据帧中,例如

df1 ABC 0 0 1 2 1 0 1 0 2 1.2 1 1 3 2 1 2

df2 ABC 0 0 1 2 1 0 1 0 2 0.2 1 2

df3 ABC 0 0 1 2 1 0 1 0 2 1.2 1 1 3 2 1 4 4 1 2 2 5 2.3 3 0

i would like to get something like 我想得到像

df_big ABCABCABC 0 0 1 2 0 1 2 0 1 2 1 0 1 0 0 1 0 0 1 0 2 1.2 1 1 0.2 1 2 1.2 1 1 3 2 1 2 2 1 4 4 1 2 2 5 2.3 3 0 is this something that can be done in pandas? df_big ABCABCABC 0 0 1 2 0 1 2 0 1 2 1 0 1 0 0 1 0 0 1 0 2 1.2 1 1 0.2 1 2 1.2 1 1 3 2 1 2 2 1 4 4 1 2 2 5 2.3 3 0可以在熊猫身上做到吗?

You could use pd.concat : 您可以使用pd.concat

df_big = pd.concat([df1, df2, df3], axis=1)

yields 产量

     A   B   C    A   B   C    A  B  C
0  0.0   1   2  0.0   1   2  0.0  1  2
1  0.0   1   0  0.0   1   0  0.0  1  0
2  1.2   1   1  0.2   1   2  1.2  1  1
3  2.0   1   2  NaN NaN NaN  2.0  1  4
4  NaN NaN NaN  NaN NaN NaN  1.0  2  2
5  NaN NaN NaN  NaN NaN NaN  2.3  3  0

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

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