I have thousands csv files names as follows file_x_x.csv where x is a number between 1 and 10000, in a same folder. Each file includes a header and one row of data:
file_1_1.csv
Name Surname Age Address
Michael O'Donnel 22 George St.
file_2_2.csv
Name Surname Age Address
Mary Jane 34 Camden St.
and so on.
I am looking for creating one single file including all these rows:
final_file.csv
Name Surname Age Address
Michael O'Donnel 22 George St.
Mary Jane 34 Camden St.
...
My approach:
import pandas as pd
import glob
path = # add path
all_files = glob.glob(path + ".csv") # look for all the csv files in that folder. Probably this is not the right code for looking at them
file_list = []
for filename in all_files:
df = pd.read_csv(filename)
file_list(df)
I do not know how to create one unique file at the end. Can you have a look at the code above and tell me how to get the desired output and if I missed something?
,not a space, so pandas won't read the values correctly.sep=" ", pandas wouldn't have loaded the csv in the example correctly, since the addresses areGeorge St.andCamden St..csvand read them and append then in one dataframe. If you have list of dataframe which generated from a for look then usepd.concat[df1, df2]and outside the for loop save it.