我正在尝试读取列表中的多个数据文件,如下所示:
for i in excels:
df2 = pd.read_csv(i, on_bad_lines='skip')
dfs.append(df2)
在本地运行它时,它运行得很好,但是在部署时,它显示了以下错误:
TypeError at /rfid-dumpdownload/
read_csv() got an unexpected keyword argument 'on_bad_lines'
on_bad_lines
甚至在文档中,那么为什么它不接受它呢?
发布于 2022-05-12 06:06:33
原因是使用较老的熊猫版本,在熊猫1.4.0下:
on_bad_lines{“错误”、“警告”、“跳过”}或可调用的默认错误
Specifies what to do upon encountering a bad line (a line with too many fields). Allowed values are :
‘error’, raise an Exception when a bad line is encountered.
‘warn’, raise a warning when a bad line is encountered and skip that line.
‘skip’, skip bad lines without raising or warning when they are encountered.
New in version 1.3.0:
callable, function with signature (bad_line: list[str]) -> list[str] | None that will process a single bad line. bad_line is a list of strings split by the sep. If the function returns None, the bad line will be ignored. If the function returns a new list of strings with more elements than expected, a ParserWarning will be emitted while dropping extra elements. Only supported when engine="python"
New in version 1.4.0.
发布于 2022-11-01 13:37:35
使用error_bad_lines
参数而不是on_bad_lines
。
在新版本的熊猫中,error_bad_lines
被on_bad_lines
取代
https://stackoverflow.com/questions/72210768
复制相似问题