Python之读取csv文件

转载于:https://www.cnblogs.com/guochangyu/p/7788414.html,感谢分享;

普通方法读取:

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 @ 2018-06-27 20:57  飞哥霸气  阅读(172)  评论(0)    收藏  举报