extract rows and filenames from multiple csv files

后端 未结 5 436
醉酒成梦
醉酒成梦 2021-01-17 02:28

I have multiple csv files with date as filename (20080101.csv to 20111031.csv) in a folder. The csv files have common headers. The csv file looks like this:



        
5条回答
  •  感情败类
    2021-01-17 02:47

    if you know that you have one file for each day, no missing day, then i'd use glob('*.csv') to get list of file names, open one bye one, then read like Tyler is doing

    if you konw that there are days where file is missing i'd use datetime to star with datetime.date(2008,1,1) and loop incrementing by one day. then for each of day i compose file name using .strftime() + '.csv', and try process file (if no file, just write a recode with NA)

提交回复
热议问题