0

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?

Dornteufel
  • 103
  • 1
  • 6
  • 1
    It seems like your original DFs are written to CSV using `df.to_csv()` - which adds the unnamed index column. You can fix it at the source by passing `index=False` to `to_csv`: https://stackoverflow.com/questions/36519086/how-to-get-rid-of-unnamed-0-column-in-a-pandas-dataframe-read-in-from-csv-fil – rdas Dec 05 '21 at 12:49
  • 2
    Does this answer your question? [How do I combine two dataframes?](https://stackoverflow.com/questions/12850345/how-do-i-combine-two-dataframes) – Tomerikoo Dec 05 '21 at 15:34

1 Answers1

0

Use join:

df1.join(df2)

Have fun!