Guys, I here have 200 separate csv files named from SH (1) to SH (200). I want to merge them into a single csv file. How can I do it?
To merge all CSV files, use the GLOB module. The os. path. join() method is used inside the concat() to merge the CSV files together.
The Command Prompt tool, aka CMD, is a Windows Explorer feature; for this feature to work accurately, make sure you have stored only the CSV files you will merge into one Excel file into one folder. 1. Go to the folder storing your CSV files and press down Shift as you right-click the folder and select “Copy path”.
As ghostdog74 said, but this time with headers:
fout=open("out.csv","a") # first file: for line in open("sh1.csv"): fout.write(line) # now the rest: for num in range(2,201): f = open("sh"+str(num)+".csv") f.next() # skip the header for line in f: fout.write(line) f.close() # not really needed fout.close()
Why can't you just sed 1d sh*.csv > merged.csv
?
Sometimes you don't even have to use python!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With