简体   繁体   中英

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. 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?

You could use 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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