csv files for python code example
Example 1: how to open csv file in python
import pandas as pd # pip install pandas
#read the CSV file
data_file = =pd.read_csv('some_file.csv')
print(data_file)
Example 2: python csv
>>> import csv
>>> with open('names.csv', newline='') as csvfile:
... reader = csv.DictReader(csvfile)
... for row in reader:
... print(row['first_name'], row['last_name'])
...
Eric Idle
John Cleese
>>> print(row)
{'first_name': 'John', 'last_name': 'Cleese'}