cvs文件的处理

一、cvs文件处理之前

1、with...as的使用

with语句用于异常处理,封装了 try…except…finally编码范式.

file = open('./test_runoob.txt', 'w')
try:
    file.write('hello world')
finally:
    file.close()

等于

with open('./test_runoob.txt', 'w') as file:
    file.write('hello world !')

2、open()的使用

https://www.runoob.com/python/python-files-io.html

创建一个file对象,用open()打开文件赋值

file object = open(file_name [, access_mode][, buffering])

access_mode决定了打开文件的模式(默认”r=只读”)

二、cvs库

https://docs.python.org/zh-cn/3/library/csv.html

1、读取csv.reader()

从csvfile读取的每一行会以字符串列表的形式返回

csv.reader(csvfile, delimiter=’’,quotechar=’’)
delimiter参数用来指明分隔符,quotechar参数表示引用符

2、写入csv.writer()

参数同上

由于csv库无法满足要求,于是尝试改用pandas库(原因以后补充)

三、pandas库

https://www.runoob.com/pandas/pandas-tutorial.html