0

How do i download a CSV file from a url in Jupyter notebook? I know how to use wget command in Google colab platform but in case of Jupyter notebook what should i do?

Ankan
  • 9
  • 4
  • 1
    Google Colab also provides you with a jupyter notebook. What is the actual problem you are facing. You can use `! wget ` to download the file – techytushar Dec 13 '19 at 14:29

3 Answers3

1

If you have a direct link to the URL you can just enter the URL directly in pandas to get the file:

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')))

Code is from this question: Pandas read_csv from url

Have a look at that as well maybe :)

Dominique Paul
  • 1,623
  • 2
  • 18
  • 31
  • 1
    you can read directly `pd.read_csv("https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv")`. And you have it even in your link :) – furas Dec 13 '19 at 15:17
  • 1
    Thank you so much, it worked. Actually i was having a problem in the last line as i was just using the read command on the csv. Can you explain the remaining part of the last line i.e. (io.StringIO(s.decode('utf-8'))) – Ankan Dec 14 '19 at 06:59
0
import pandas as pd

data = pd.read_csv("https://abc/xyz.csv")

For more, check the documentation:

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html

Dipen Gajjar
  • 1,338
  • 14
  • 23
-1

You can use:

def download_csv_to_df(urllink):
    converted_dataframe = pd.read_csv(urllink)
    return converted_dataframe
fcdt
  • 2,371
  • 5
  • 14
  • 26
Amit
  • 1