Supose I have csv file named “liz.csv” which contains :
Serial,Name,Course,City 1,Raiyan,Python,London 2,Joel,Css,Kyoto 3,Samantha,Python,Paris 4,Porth,Java,Tokyo
How can I import this file into lists using python?
Thank you
Python has a built-in csv module, which provides a reader class to read the contents of a csv file.You can use that:
from csv import reader with open('your file name.csv', 'r') as read_obj: csv_reader = reader(read_obj) list_of_rows = list(csv_reader) print(list_of_rows)
You can also use pandas to read csv files without headers:
import pandas as pd df = pd.read_csv('your file name.csv', delimiter=',') list_of_rows = [list(row) for row in df.values] print(list_of_rows)
Hope you understand now .
If not fell free to ask me any question.