January 2019
Beginner
318 pages
8h 23m
English
Python has an in-built module, csv, which we are going to use here to work with CSV files. We will use the csv.reader module to read a CSV file. Create a script called csv_read.py and write the following content in it:
import csvcsv_file = open('test.csv', 'r')with csv_file: read_csv = csv.reader(csv_file) for row in read_csv: print(row)
Run the script and you will get the following output:
student@ubuntu:~$ python3 csv_read.py
Following is the output:
['Region', 'Country', 'Item Type', 'Sales Channel', 'Order Priority', 'Order Date', 'Order ID', 'Ship Date', 'Units Sold']['Sub-Saharan Africa', 'Senegal', 'Cereal', 'Online', 'H', '4/18/2014', '616607081', '5/30/2014', '6593']['Asia', 'Kyrgyzstan', 'Vegetables', 'Online', ...
Read now
Unlock full access