本文主要为大家讲解Python读取CSV文件的三种方式,希望对大家有帮助!

普通方法读取:

with open(“fileName.csv”) as file:


 


    for line in file:


 


       print line


 


用CSV标准库读取:

import csv


 


csv_reader = csv.reader(open(“fileName.csv”))


 


for row in csv_reader:


 


    print row


 


用pandas读取:

import pandas as pd


 


data = pd.read_csv(“fileName.csv”)


 


print data


 


data = pd.read_table(“fileName.csv”,sep=”,”)


 

print data

以上就是“Python如何批量读取CSV文件”的详细内容,想了解更多请持续关注90代码网!