代码
import pandas as pd with open(r"D:/Edge Install/kettle/第七章/lecture.txt") as file_obj: df = pd.read_csv(file_obj, sep='\t') df.to_csv(r"D:/Edge Install/kettle/第七章/new 1.csv") df[df['工龄'] > 3].to_csv(r"D:/Edge Install/kettle/第七章/new 1.csv")
lecture.txt内容:
id lecturer 级别 工龄
1 liangquan B 10
2 moyi B 9
3 mengjian C 5
4 huangnan A 3
5 yanhao C 7
解决方法:最下行添加
print(df.columns.tolist())
遍历列名
发现中文是乱码,将”工龄“换成”宸ラ緞“后运行成功
所以问题出在乱马上