Aan de slagGa gratis aan de slag

Importing flat files from the web: your turn!

You are about to import your first file from the web! The flat file you will import will be 'winequality-red.csv' from the University of California, Irvine's Machine Learning repository. The flat file contains tabular data of physiochemical properties of red wine, such as pH, alcohol content and citric acid content, along with wine quality rating.

The URL of the file is

'https://assets.datacamp.com/production/course_1606/datasets/winequality-red.csv'

After you import it, you'll check your working directory to confirm that it is there and then you'll load it into a pandas DataFrame.

Deze oefening maakt deel uit van de cursus

Intermediate Importing Data in Python

Cursus bekijken

Oefeninstructies

  • Import the function urlretrieve from the subpackage urllib.request.
  • Assign the URL of the file to the variable url.
  • Use the function urlretrieve() to save the file locally as 'winequality-red.csv'.
  • Execute the remaining code to load 'winequality-red.csv' in a pandas DataFrame and to print its head to the shell.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import package
from ____ import ____

# Import pandas
import pandas as pd

# Assign url of file: url


# Save file locally


# Read file into a DataFrame and print its head
df = pd.read_csv('winequality-red.csv', sep=';')
print(df.head())
Code bewerken en uitvoeren