Get startedGet started for free

Opening and reading flat files from the web

You have just imported a file from the web, saved it locally and loaded it into a DataFrame. If you just wanted to load a file from the web into a DataFrame without first saving it locally, you can do that easily using pandas. In particular, you can use the function pd.read_csv() with the URL as the first argument and the separator sep as the second argument.

The URL of the file, once again, is

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

This exercise is part of the course

Intermediate Importing Data in Python

View Course

Exercise instructions

  • Assign the URL of the file to the variable url.
  • Read file into a DataFrame df using pd.read_csv(), recalling that the separator in the file is ';'.
  • Print the head of the DataFrame df.
  • Execute the rest of the code to plot histogram of the first feature in the DataFrame df.

Hands-on interactive exercise

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

# Import packages
import matplotlib.pyplot as plt
import pandas as pd

# Assign url of file: url


# Read file into a DataFrame: df


# Print the head of the DataFrame
print(____)

# Plot first column of df
df.iloc[:, 0].hist()
plt.xlabel('fixed acidity (g(tartaric acid)/dm$^3$)')
plt.ylabel('count')
plt.show()
Edit and Run Code