#-*- coding:utf-8 -*-

import os
import os.path
import csv
rootdir = "/Users/ying/Documents"     # folder stores csv files

for parent,dirnames,filenames in os.walk(rootdir):
    for filename in filenames:
        abs_path = os.path.join(parent,filename)
        if ".csv" in abs_path:
            print abs_path
            #对每个文件进行处理
            with open(abs_path, 'rb') as csvfile:
                reader = csv.reader(csvfile)
                rows = [row for row in reader]
                header = rows[0]
                for rowOne in rows[1:]:
                    json_row = {}
                    for i in range(0,len(rowOne)):
                        json_row[header[i]] = rowOne[i]
                    print json_row

 

相关文章:

  • 2022-12-23
  • 2022-01-06
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
猜你喜欢
  • 2021-06-12
  • 2022-02-17
  • 2021-10-03
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案