VOOZH about

URL: https://www.geeksforgeeks.org/python/read-a-csv-into-list-of-lists-in-python/

⇱ Read a CSV into list of lists in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Read a CSV into list of lists in Python

Last Updated : 23 Jul, 2025

In this article, we are going to see how to read CSV files into a list of lists in Python.

Method 1: Using CSV module

  • We can read the CSV files into different data structures like a list, a list of tuples, or a list of dictionaries.
  • We can use other modules like pandas which are mostly used in ML applications and cover scenarios for importing CSV contents to list with or without headers.

Example 1:

In this example, we are reading a CSV file and converting the string into the list.

👁 Image
 

Output:

[['JAN', 34, 360, 417], ['FEB', 31, 342, 391], ['MAR', 36, 406, 419], ['APR', 34, 396, 461],

 ['MAY', 36, 420, 472], ['JUN', 43, 472, 535], ['JUL', 49, 548, 622], ['AUG', 50, 559, 606], 

 ['SEP', 40, 463, 508], ['OCT', 35, 407, 461], ['NOV', 31, 362, 390], ['DEC', 33, 405, 432]]

Example 2:

In this example, we are reading a CSV file and iterating over lines in the given CSV.

👁 Image
 

Output:

👁 Image
 

Method 2: Using Pandas

You can use the pandas library for this which has an inbuilt method to convert values to a list. Pandas.values property is used to get a numpy.array and then use the tolist() function to convert that array to list.

Note: For more information refer Read CSV Into List Using Pandas

Output:

👁 Image
 
Comment
Article Tags: