laika222
10/24/2018 - 8:35 PM

Load CSV File and Query

#FIRST METHOD OF IMPORTING, import csv file using the csv module
import csv

path = r'C:\Users\K\Dropbox\Code Examples\Python\Python Full Work\import_base.csv'
with open(path, 'r') as csv_file:
    csv_reader = csv.reader(csv_file)

    print(csv_file)

    for row in csv_reader:
        print(row)

#SECOND METHOD OF IMPORTING, import csv file using pandas and numpy
import pandas as pd
import numpy as np

datafile = pd.read_csv('C:\\Users\\K\\Dropbox\\Code Examples\\Python\\Python Full Work\\import_base.csv')

#shows datafile, does same as #datafile
datafile 

print(datafile)

datafile['Fiscal Year']

datafile["Fiscal Year"].mean()

datafile["Fiscal Year"].max()

datafile["Fiscal Year"].min()

datafile.loc[datafile['Fiscal Year'] == 2017]

datafile.loc[datafile['Fiscal Year'] != 2017]