read_csv() got an unexpected keyword argument 'error_bad_lines'

时间: 2023-11-19 20:06:13 浏览: 136
这个错误通常是因为你正在使用的 Pandas 版本太旧,不支持 `error_bad_lines` 参数。这个参数是在 Pandas 1.0.0 版本中引入的,用于控制在读取 CSV 文件时遇到错误行时的行为。如果你的 Pandas 版本太旧,建议升级到最新版本。 如果你已经使用的是最新版本的 Pandas,那么可能是因为你正在使用的是较旧的 Python 版本,而该参数只在 Python 3 中可用。如果是这种情况,你需要将 Python 升级到 3.x 版本。
相关问题

typeerror: read_csv() got an unexpected keyword argument 'error_bad_lines

TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines' 是一个错误提示,表明read_csv() 函数中出现了一个意外的关键字参数 'error_bad_lines'。 这个错误通常是因为pandas版本较低,不支持 'error_bad_lines' 关键字参数而导致的。 'error_bad_lines' 是用于指定当读取csv文件时,是否忽略错误行的参数。该参数在较新的pandas版本中才被添加进来。 要解决这个问题,可以考虑以下两种方法: 1. 升级pandas版本:在命令行中使用以下命令来升级pandas:'pip install --upgrade pandas'。通过升级pandas到最新版本,就可以使用 'error_bad_lines' 参数来解决这个问题。 2. 采用其他方法处理错误行:如果无法升级pandas版本,可以通过其他方式处理错误行。比如,可以指定参数 'on_bad_lines' 为 'skip',这样就会在遇到错误行时跳过并继续读取文件。示例如下: ``` import pandas as pd df = pd.read_csv('file.csv', on_bad_lines='skip') ``` 这样,当遇到错误行时,就会跳过该行并继续读取其他数据。 无论采用哪种方法,都可以解决 'TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines'' 这个错误。

TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines'

如果你在使用 Pandas 库的 `read_csv` 函数时遇到了 `TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines'` 的错误,这通常是因为你使用的 Pandas 版本较低,不支持 `error_bad_lines` 参数。 在 Pandas 1.0.0 版本之前,`error_bad_lines` 参数并不受支持。如果你使用的是较早的 Pandas 版本,你可以尝试使用 `skiprows` 参数来跳过包含错误数据的行。例如: ```python import pandas as pd df = pd.read_csv('filename.csv', skiprows=[n for n in range(1, 4)]) ``` 在这个例子中,`skiprows` 参数指定了要跳过的行号。在这个例子中,我们跳过了第二行到第四行,以避免读取包含错误数据的行。 如果你想要使用 `error_bad_lines` 参数,你可以尝试升级你的 Pandas 版本,或者使用其他方法来处理包含错误数据的行。

相关推荐

pandas 2.0.2版本 from bs4 import BeautifulSoup import pandas as pd import requests import time df = pd.read_csv('playlist.csv', header=None,error_bad_lines=False, names=['url', 'title', 'play', 'user']) headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' } for i in df['url']: time.sleep(2) url = 'https://music.163.com' + i response = requests.get(url=url, headers=headers) html = response.text soup = BeautifulSoup(html, 'html.parser') # 获取歌单标题 title = soup.select('h2')[0].get_text().replace(',', ',') # 获取标签 tags = [] tags_message = soup.select('.u-tag i') for p in tags_message: tags.append(p.get_text()) # 对标签进行格式化 if len(tags) > 1: tag = '-'.join(tags) else: tag = tags[0] # 获取歌单介绍 if soup.select('#album-desc-more'): text = soup.select('#album-desc-more')[0].get_text().replace('\n', '').replace(',', ',') else: text = '无' # 获取歌单收藏量 collection = soup.select('#content-operation i')[1].get_text().replace('(', '').replace(')', '') # 歌单播放量 play = soup.select('.s-fc6')[0].get_text() # 歌单内歌曲数 songs = soup.select('#playlist-track-count')[0].get_text() # 歌单评论数 comments = soup.select('#cnt_comment_count')[0].get_text() # 输出歌单详情页信息 print(title, tag, text, collection, play, songs, comments) # 将详情页信息写入CSV文件中 with open('music_message.csv', 'a+', encoding='utf-8-sig') as f: f.write(title + ',' + tag + ',' + text + ',' + collection + ',' + play + ',' + songs + ',' + comments + '\n') # 获取歌单内歌曲名称 li = soup.select('.f-hide li a') for j in li: with open('music_name.csv', 'a+', encoding='utf-8-sig') as f: f.write(j.get_text() + '\n') 出错 read_csv() got an unexpected keyword argument 'error_bad_lines'

最新推荐

recommend-type

基于Python的蓝桥杯竞赛平台的设计与实现

【作品名称】:基于Python的蓝桥杯竞赛平台的设计与实现 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】:基于Python的蓝桥杯竞赛平台的设计与实现
recommend-type

python实现基于深度学习TensorFlow框架的花朵识别项目源码.zip

python实现基于深度学习TensorFlow框架的花朵识别项目源码.zip
recommend-type

3-9.py

3-9
recommend-type

郊狼优化算法COA MATLAB源码, 应用案例为函数极值求解以及优化svm进行分类,代码注释详细,可结合自身需求进行应用

郊狼优化算法COA MATLAB源码, 应用案例为函数极值求解以及优化svm进行分类,代码注释详细,可结合自身需求进行应用
recommend-type

563563565+3859

5635356
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。