MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Intermediate Importing Data in Python

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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 dan Jalankan Kode