Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable import the dataset from a url

I am told to import data from URL and create pandas data frame and use sep= "|" while reading the data.
I tried this

import requests
r = requests.get(url)
data = r.text
df = pd.DataFrame(data)

and I getting this error: ValueError: DataFrame constructor not properly called!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can directly call read_csv() on the URL, making sure to specify the separator:

pd.read_csv('https://raw.githubusercontent.com/justmarkham/DAT8/master/data/u.user',
 sep='|')

Giving you:

user_id age gender  occupation  zip_code
0   1   24  M   technician  85711
1   2   53  F   other   94043
2   3   23  M   writer  32067
3   4   24  M   technician  43537
4   5   33  F   other   15213
... ... ... ... ... ...
938 939 26  F   student 33319
939 940 32  M   administrator   02215
940 941 20  M   student 97229
941 942 48  F   librarian   78209
942 943 22  M   student 77841
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading