简体   繁体   中英

CSV Merge in Python (Multiple files)

I've recently started learning Python. I came across a problem and thought if somebody can help me. I am trying to merge .csv files which are in same directory. A directory with today's date is created everyday and has one more directory in it for city and city directory has the following files.

vkSummary1abc   
vkSummary2gbb   
vkSummary3def   
vkDetail1abc
vkDetail2gbb   
vkDetail3def

I am trying to merge all vkDetail files. There can be 3 or more files in the directory. The script should ask the user first which date and city he is trying to run the script on and from that date directory and city directory all the detail files should be merged. The header should only be there once and then the data.

Once you have the date and city from the user you can use glob.glob() to get all the files in the corresponding directory. From there just open each file in turn, skip past the header row, and write into the result file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM