# 1.导入包import pandas as pd# 2读入数据readFile = pd.read_csv('输出路径',encoding='gb2312')for record in readFile.values: print(record)
至此就完成了整个过程
如果有Nan怎么处理呢?
我们可以在readFile后面加入以下内容:
readFile = readFile.fillna('del_token')在for record in readFile.values后面加入一个while循环 record = list(record)while ('del_token' in record): record.remove('del_token') print(record)整个代码看起来就像这样子了:# 1.导入包import pandas as pd# 2读入数据readFile = pd.read_csv('输出路径',encoding='gb2312')# 给Nan赋值readFile = readFile.fillna('del_token')for record in readFile.values:# 转换列表删除Nanwhile ('del_token' in record): record.remove('del_token')# 打印 print(record)