1

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)
4
  • 3
    works for me. What error do you get? Commented Nov 18, 2022 at 15:42
  • I don't get any error but it doesn't do anything either. Commented Nov 18, 2022 at 15:45
  • 3
    It creates a dataframe and assigns it to a variable named df. You can see a sample of the contents of this dataframe with print(df.head()) Commented Nov 18, 2022 at 15:46
  • 1
    Try to print df with print(df) to see what happens Commented Nov 18, 2022 at 15:47

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.