Home > Enterprise >  Problem reading CSV file from URL in pandas python
Problem reading CSV file from URL in pandas python

Time:08-19

I'm trying to read csv file in pandas from this url:

https://www.dropbox.com/s/uh7o7uyeghqkhoy/diabetes.csv

By doing this:

url = "https://www.dropbox.com/s/uh7o7uyeghqkhoy/diabetes.csv">
c = pd.read_csv(url)

Or by doing this:

import pandas as pd
import io
import requests
url="https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv"
s=requests.get(url).content
c=pd.read_csv(io.StringIO(s.decode('utf-8')))

And i still get the same error message:

ParserError: Error tokenizing data. C error: Expected 1 fields in line 3, saw 2

CodePudding user response:

Simply:

import pandas as pd
df = pd.read_csv("https://www.dropbox.com/s/uh7o7uyeghqkhoy/diabetes.csv?dl=1")
print(df)

You require a ?dl=1 at the end of your link.

Related

CodePudding user response:

Add ?dl=1 to the end of the URL

import pandas as pd

url = "https://www.dropbox.com/s/uh7o7uyeghqkhoy/diabetes.csv?dl=1"
c = pd.read_csv(url)

print(c)

How to download dropbox csv file to pandas

  • Related