I have 3 CSV files (separated by ',') with no headers and need to concat them into one file:
file1.csv
United Kingdom John
file2.csv
France Pierre
file3.csv
Italy Marco
expected result:
United Kingdom John
France Pierre
Italy Marco
my code:
import pandas as pd
df = pd.read_csv('path/to/file1.csv', sep=',')
df1 = pd.read_csv('path/to/file2.csv', sep=',')
df2 = pd.read_csv('path/to/file3.csv', sep=',')
df_combined = pd.concat([df,df1,df2])
df_combined.to_csv('path/to/output.csv')
the above gives me data merged but it added rows from my CSV files as new columns and rows, instead to add only new rows to existing two columns:
United Kingdom John
France Pierre
Italy Marco
Could someone please help with this? Thank you in advance!
print(df.columns)
... you could also print df.shape tuples. I suspect you import first row as column names (you need to useheader=None
argument in read_csv) – predmod