首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >read_csv()得到了一个意外的关键字参数'on_bad_lines‘

read_csv()得到了一个意外的关键字参数'on_bad_lines‘
EN

Stack Overflow用户
提问于 2022-05-12 06:04:11
回答 2查看 2.5K关注 0票数 1

我正在尝试读取列表中的多个数据文件,如下所示:

代码语言:javascript
运行
复制
for i in excels:
    df2 = pd.read_csv(i, on_bad_lines='skip')
    dfs.append(df2)

在本地运行它时,它运行得很好,但是在部署时,它显示了以下错误:

代码语言:javascript
运行
复制
TypeError at /rfid-dumpdownload/
read_csv() got an unexpected keyword argument 'on_bad_lines'

on_bad_lines甚至在文档中,那么为什么它不接受它呢?

EN

回答 2

Stack Overflow用户

发布于 2022-05-12 06:06:33

原因是使用较老的熊猫版本,在熊猫1.4.0下:

on_bad_lines{“错误”、“警告”、“跳过”}或可调用的默认错误

代码语言:javascript
运行
复制
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.
票数 1
EN

Stack Overflow用户

发布于 2022-11-01 13:37:35

使用error_bad_lines参数而不是on_bad_lines

在新版本的熊猫中,error_bad_lineson_bad_lines取代

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72210768

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档