Python读取CSV文件

普通方法读取:

 

1 with open("fileName.csv") as file:
2     for line in  file:
3         print line

 

用CSV标准库读取:

 

1 import csv
2 csv_reader = csv.reader(open("fileName.csv"))
3 for row in csv_reader:
4     print row

 

用pandas读取:

 

1 import pandas as pd
2 data = pd.read_csv("fileName.csv")
3 print data
4 
5 data = pd.read_table("fileName.csv",sep=",")
6 print data

 

posted @ 2017-11-05 19:49  __迷途的羔羊  阅读(44111)  评论(0编辑  收藏  举报