提问人:Ryan 提问时间:4/16/2023 最后编辑:Ajeet VermaRyan 更新时间:4/18/2023 访问量:36
不断获取 ParseError
Keep getting ParseError
问:
我正在尝试阅读这个txt文件。但是由于某些原因,我一直收到此错误:
ParserError:标记数据时出错。C 错误:第 27 行中预期有 1 个字段,看到 367
以下是我的代码:
df = pd.read_csv('githublink')
df.read()
答:
0赞
Rukon
4/16/2023
#1
您必须使用 GitHub 中的链接,因为您提供的链接会返回一个页面。Raw
HTML
import pandas as pd
import io
import requests
url="https://raw.githubusercontent.com/ryan-2121/data/595128c71d558943d0fbc518dcca618a7273d058/product_care" # using the raw link from github
s=requests.get(url).content
df = pd.read_csv(io.StringIO(s.decode()), sep=",", header=None, names = ['Region','Market','Chart',"Name","Unit","Source","2014","2015","2016","2017",'2018',"2019","2020","2021","2022",'2023',"2024","2025","2026","2027"] )
df.drop(index=df.index[0], axis=0, inplace=True) # The first row contains the column name, hence dropping it.
评论