467,120 Members | 1,246 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,120 developers. It's quick & easy.

How do I import a dataset into jupyter notebook from a URL?

2Bits
I have tried these two codes and none of them seems to work. Can any of you help?

Expand|Select|Wrap|Line Numbers
  1. from numpy import loadtxt
  2. from urlib.request import urlopen
  3.  
  4. url= 'https://think.cs.vt.edu/corgis/datasets/python/electricity/electricity.data'
  5.  
  6. raw_data = urlopen(url)
  7. dataset = loadtxt(raw_data, dtype = 'str', delimiter = ",")
  8.  
  9. print(dataset.shape)
  10. print()
  11. print(dataset[1:20])
Expand|Select|Wrap|Line Numbers
  1. import requests
  2. import pandas as pd
  3. URL ='https://think.cs.vt.edu/corgis/datasets/python/electricity/electricity.data'
  4. r = requests.get(URL)
  5. # a= eval(r.content) Never user eval for online texts
  6. df = pd.DataFrame(r.json())
Dec 7 '20 #1
  • viewed: 1889
Share:

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by F. GEIGER | last post: by
reply views Thread by dimitri pater | last post: by
8 posts views Thread by Kreedz | last post: by
1 post views Thread by Ed Bacon | last post: by
4 posts views Thread by Iain Kirk | last post: by
2 posts views Thread by David Richards | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.