简体   繁体   中英

how to concatenate two csv files?

I have two csv files and I want to make them to be one csv file

df1:
      aa  bb  cc   
   0  65  33  A
   1  50  32  B
   2  40  23  C

df2:
      0   1   2   
   0  70  40  7
   1  50  30  8
   2  40  23  9

the result should like this:

      aa  bb  cc  0   1   2
   0  65  33  A   70  40  7
   1  50  32  B   50  30  8
   2  40  23  C   40  23  9

but I get this:
      aa  bb  cc Unnamed  0   1   2
   0  65  33  A     0     70  40  7
   1  50  32  B     1     50  30  8
   2  40  23  C     2     40  23  9

here's my code:

df_new = pd.concat([df1, df3], axis=1)
result = df_new.to_csv("C:/Users/AZ/.spyder-py3/DATASET1/new.csv")

Can anyone help?

Use join:

df1.join(df2)

Have fun!

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