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!


Solution 1:

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