sansa
sansa

Reputation: 21

downloading CSV file in python using pandas

I am trying to download a csv file to python. For some reason I can not do it. I suppose I need to add an additional argument to read_csv?

import pandas as pd

url = "https://raw.githubusercontent.com/UofGAnalyticsData/"\
          "DPIP/main/assesment_datasets/assessment3/starwars.csv"

df = pd.read_csv(url)

Upvotes: 1

Views: 673

Answers (1)

Salman Ahmad
Salman Ahmad

Reputation: 21

The code you attempt is downloading the content from the url and pasting it in the data frame named 'df'. You need to save the output csv by using the following line. You will find the output file in the same directory where the python script is saved.

import pandas as pd

url = "https://raw.githubusercontent.com/UofGAnalyticsData/"\
          "DPIP/main/assesment_datasets/assessment3/starwars.csv"

df = pd.read_csv(url)
df.to_csv('output.csv')

Upvotes: 1

Related Questions