Keep getting ParseError

41 Views Asked by At

I'm trying to read this txt file. But for some reasons, I keep getting this error:

ParserError: Error tokenizing data. C error: Expected 1 fields in line 27, saw 367

Below is my code:

df = pd.read_csv('githublink')  
df.read()

Data from the githublink:

1

There are 1 best solutions below

0
Rukon On

You have to use the Raw link from GitHub as the link you have provided returns an HTML page.

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.