filepath = "..\folder\data.tsv"
df = pd.read_csv(filepath)
OSError: [Errno 22] Invalid argument: '..\folder\\data.tsv'
应该写成
filepath = r"..\folder\data.tsv"
df = pd.read_csv(filepath)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
df = pd.read_csv(filepath)
ParserError: Error tokenizing data. C error: Expected 6 fields in line 1117367, saw 7
应该写成
df = pd.read_csv(filepath, sep='delimiter')
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.
return func(*args, **kwargs)
应该写成
df = pd.read_csv(filepath, sep='delimiter', engine='python')
处理CSV文件的常见错误及解决方案
这篇博客探讨了在使用pandas读取CSV文件时遇到的三个常见问题:1) OSError涉及到路径的正确格式,解决方案是使用原始字符串(r''')来避免转义字符;2) ParserError提示数据解析错误,可能是因为字段数量不匹配,修正分隔符可以解决;3) ParserWarning提到了引擎不支持正则分隔符,应指定使用'python'引擎。通过这些调整,可以确保数据正确加载。
3976

被折叠的 条评论
为什么被折叠?



