Hello guys I have a program where i have a multiple csv file and i want to append that csv files Its a simple ex what i have and what i want..
File1.csv:
A B C D
1 2 3 4
2 3 4 5
File2.csv:
A B C D
8 8 8 8
9 9 9 9
outputFile.csv:
A B C D
1 2 3 4
2 3 4 5
8 8 8 8
9 9 9 9
This is the reqiured output for getting this i have written a code which works fine ..
file1 = "File1.csv"
df1= pd.read_csv(file1)
file2 = "File2.csv"
df2= pd.read_csv(file2)
results = df1.append(df2)
results.to_csv("outputFile.csv", index=False)
This works fine but now i'm getting the Input file from UI where i'm getting the files in List so for that i have written a code but its not working
datafiles = ["File1.csv","File2.csv"]
dataframes=[]
# df = pd.DataFrame()
for files in datafiles:
df1= pd.read_csv(files)
dataframes.append(df1)
dataframes.to_csv("mergeOutput.csv", index=False)
I don't want to read all files separately that why i have used the for loops and store all the data to the dataframes but its not correct way i guess please suggest me the correct way how to do it and i also want to remove the duplicates from file please let me know if anyhting is not clear...thanks in advance.
As suggest @Thotsaphon Sirikutta Import multiple csv files into pandas and concatenate into one DataFrame now i'm able to get the output file as i need but i'm getting everytime getting 3 or 4 extra columns named as "Unnamed" which is empty so please tell me why i'm getting extra columns how to remove it without using drop() this is code
datafiles = ["File1.csv","File2.csv"]
dfs=[]
for filename in datafiles:
dfs.append(pd.read_csv(filename))
mergeData = pd.concat(dfs,sort=False)
mergeData.to_csv("mergeOutput.csv", index=False)