Get startedGet started for free

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.

This exercise is part of the course

Intermediate Importing Data in Python

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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())
Edit and Run Code