VOOZH about

URL: https://www.geeksforgeeks.org/python/python-read-csv-columns-into-list/

⇱ Python - Read CSV Columns Into List - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python - Read CSV Columns Into List

Last Updated : 21 Jun, 2025

CSV (Comma-Separated Values) files are widely used to store tabular data. Each line in a CSV file corresponds to a data record, and each record consists of one or more fields separated by commas. In this article, you’ll learn how to extract specific columns from a CSV file and convert them into Python lists.

In this article we’ll explore two common methods:

  1. Using the Pandas library
  2. Using Python’s built-in csv module

To use the file used in this article, click here.

Method 1: Using Pandas

Pandas is a powerful library for data manipulation. The read_csv() function reads the CSV file into a DataFrame, and then tolist() converts column data to Python lists.

Approach:

  • Import pandas.
  • Use read_csv() to load the file.
  • Access specific columns.
  • Convert each column to a list using .tolist().
  • Print the lists.

Example:

Output:

👁 Image

Method 2: Using csv.DictReader

If you prefer using built-in libraries or want more control over parsing, the csv module is a good alternative. DictReader reads the file as a dictionary where each row is mapped using column headers as keys.

Approach:

  • Import the csv module.
  • Open the file in read mode.
  • Use csv.DictReader() to parse rows.
  • Create empty lists for desired columns.
  • Append values to lists inside a loop.

Output:

👁 Image

Related Articles:

Comment