ITPub博客

首页 > IT职业 > IT职场 > python中如何读取csv

python中如何读取csv

IT职场 作者:ideasdo 时间:2021-09-11 10:33:22 0 删除 编辑

普通方法读取(open函数打开csv文件,然后使用for循环读取内容):

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

python学习网,大量的免费python视频教程,欢迎在线学习!

用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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4237/viewspace-2836612/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-12

  • 博文量
    0
  • 访问量
    544