import csv

2、读取csv文件

file1 = open('test1.csv', 'rb')

reader = csv.reader(file1)

rows = [row for row in reader] #csv文件每一行内容组成的二位列表

Python pandas模块

3、写入csv文件

csv.reader()返回一个DictReader对象。

csv.writer()返回一个DictWriter对象。

DictWriter.writerow()写一行。

DictWriter.writerows()写多行。

需要注意的问题是:当我们需要写csv的时候,打开文件一定要带上’b’,否则可能会往文件里输出空行。Python 3.x情况会有些不同。

相关文章:

  • 2022-12-23
  • 2021-08-09
  • 2022-02-20
  • 2021-10-06
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-10-24
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案