read_csv()

noun

say it: “REED see-ess-VEE” /ˈrid ˌsiˌɛsˈvi/

A pandas function that reads a CSV file, a spreadsheet saved as plain text, into a table that Python can sort, filter and add up.

What does read_csv() do in pandas?

read_csv() (pd.read_csv) loads a CSV file into a DataFrame: the first line becomes the column names and every other line a row. Its options pick what to load: usecols the columns, nrows how many rows, sep the separator, and na_values the words that mean missing.

import pandas as pd
sales = pd.read_csv("sales.csv", usecols=["date", "product", "units"], nrows=5)
print(sales.shape)    # (5, 3)

In a sentence

  • “One line with read_csv() loaded the market's 1,900 sales.”
  • “She passed usecols to read_csv() so only three columns came in.”

Level: Apprentice · More Python terms at this level

Updated