Python

How to read CSV file in Python

December 24, 2017
Python, Tools

TLDR; Using pandas (pip install pandas) import pandas as pd data = pd.read_csv("actors.csv").to_dict(orient="row") Using native csv.DictReader import csv with open("actors.csv") as f: data = [r for r in csv.DictReader(f)] Reading as a List Let’s say we have the following CSV file, named actors.csv. You can download this file here. The first method demonstrated in Python docs would read the file as follows: Open the file Create a CSV reader Skip first line (header) For every line (row) in the file, do something import csv with open("actors. ...