Search⌘ K
AI Features

Loading a CSV Dataset From a URL

Explore how to load CSV datasets directly from URLs using Python's pandas library. Learn to read data efficiently by selecting specific columns with usecols, limiting rows with nrows, and managing headers with skiprows to prepare data for analysis.

Loading CSV files

The CSV format is popular for storing and transferring data. Files with a .csv extension are plain text files containing data records with comma-separated values.

Let’s see how we can analyze data from a CSV file using Python by loading the file from a URL.

Python 3.8
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/CourseMaterial/DataWrangling/main/flowerdataset.csv')
print(df.head())

Let’s review the code line by line:

  • Line 1: We start by first importing the pandas library using import pandas as pd.

  • Line 2: We pass the URL of the dataset, enclosed in quotes, to the read_csv() function and save the result in the df variable.

Note: When we save the dataset inside a variable, we refer to the variable as a DataFrame. A DataFrame is a ...