Read csv file from python [duplicate]

只愿长相守 提交于 2019-11-30 16:44:22

First, make sure you converted the file from Excel to csv, using the Save As menu from Excel. Simply changing the extension doesn't work. The output you are seeing is data from Excel's native format.

Once you have converted the files, use the csv module:

import csv

for filename in os.listdir(INPUT_DIR):
   with open(os.path.join(INPUT_DIR,filename), dialect='excel-tab') as infile:
      reader = csv.reader(infile)
      for row in reader:
          print row

If you want to read raw Excel files, use the xlrd module. Here is a sample that shows how to read Excel files.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!