csv load in python code example
Example 1: csv python write
import csv
with open('names.csv', 'w') as csvfile:
fieldnames = ['first_name', 'last_name']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})
writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})
writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})
Example 2: pandas go through csv file
data = pd.read_csv(
"data/files/complex_data_example.tsv",
sep='\t'
quotechar="'",
dtype={"salary": int},
usecols=['name', 'birth_date', 'salary'].
parse_dates=['birth_date'],
skiprows=10,
na_values=['.', '??']
)