Import CSV file into List in Python
The following examples shows, how to import csv file into a list converts each row of the csv into a list using pandas in Python.
Install pandas using pip
pip install pandas
CSV File : sample.csv
Example
import pandas as pd #imports a CSV file to DataFrame format data_frame=pd.read_csv("sample.csv",delimiter=',') #Create List from DataFrame Values a=[list(row) for row in data_frame.values] print(a)
[['Ram', 25, 9638521470], ['Sam', 30, 9874563210], ['Bala', 35, 9874563215], ['Raja', 40, 9874563218]]