Good morning. I have to read a field (line) from a file in .csv and fill a certain field in the system. How should I do? For example, my .csv is mass of data for filling in a record.
Good morning. I have to read a field (line) from a file in .csv and fill a certain field in the system. How should I do? For example, my .csv is mass of data for filling in a record.
You can do it in several ways, but the most usual one is:
import csv
with open('214385.csv') as f:
f_csv = csv.reader(f)
headers = next(f_csv)
for row in f_csv:
# Process row
print(row)
link: link
Sample csv file:
obs: first line and header
Symbol,Price,Date,Time,Change,Volume
"AA",39.48,"6/11/2007","9:36am",-0.18,181800
"AIG",71.38,"6/11/2007","9:36am",-0.15,195500
"AXP",62.58,"6/11/2007","9:36am",-0.46,935000
"BA",98.31,"6/11/2007","9:36am",+0.12,104800
"C",53.08,"6/11/2007","9:36am",-0.25,360900
"CAT",78.29,"6/11/2007","9:36am",-0.23,225400
link: link
This example was taken from the book: Python Cookbook - > link