For me, learning to read .csv files in Python was difficult and tedious. However, I persevered and now I am pretty comfortable with it. In this tutorial I’ll show you a super simple way to go about reading .csv files.

1. First you’ll need a .csv file to read.. obviously.. so for this example we will use some Google stock data from yahoo finance. Just click this link and save the file to a folder.

2. You can name the folder what ever you want but just remember where it is so you will be able to navigate to it easily in the terminal.

3. Now open a text editor, I recommend Visual Studio Code from Microsoft.

4. Open the folder you saved the .csv file in and create a new file with a .py extension.

5. Add this code:



# csv file reader
#import the csv package
import csv

#create a variable to store the name of the .csv file to read
csv_data = "GOOG.csv"

#open the file and store its contents in the variable f
with open(csv_data) as f:
    #loop through and print each row
    for row in f:
        print(row)
#close the file
f.close()

6. Open a terminal and navigate to the file you just created.

-Super basic terminal commands:
ls (list files in directory)
cd directoryName (change directory to directoryName)
cd .. (go back one directory)

7. Type python3 yourfilename.py and voila. Now go get rich with all this awesome data!