我一直在Windows中使用Pandas / Python读取制表符分隔的数据文件,没有任何问题。数据文件的前三行包含注释,然后带有标题。
df = pd.read_csv(myfile,sep='\t',skiprows=(0,1,2),header=(0))
我现在正在尝试使用Mac读取此文件。(我第一次在Mac上使用Python。)出现以下错误。
pandas.parser.CParserError: Error tokenizing data. C error: Expected 1
fields in line 8, saw 39
如果将read_csv的error_bad_lines参数设置为False,则会得到以下信息,该信息一直持续到最后一行的末尾。
Skipping line 8: expected 1 fields, saw 39
Skipping line 9: expected 1 fields, saw 125
Skipping line 10: expected 1 fields, saw 125
Skipping line 11: expected 1 fields, saw 125
Skipping line 12: expected 1 fields, saw 125
Skipping line 13: expected 1 fields, saw 125
Skipping line 14: expected 1 fields, saw 125
Skipping line 15: expected 1 fields, saw 125
Skipping line 16: expected 1 fields, saw 125
Skipping line 17: expected 1 fields, saw 125
...
是否需要为encoding参数指定一个值?似乎我不必这样做,因为在Windows上读取文件效果很好。