import pandas as pd
import os

"""
Explanation: Import csv To Pandas
This file covers the process of importing excel files into a pandas dataframe.
The function used is read_csv.
Step 1
Lets start by importing pandas and os. We will be using pandas to create a dataframe from our data, and os to get file paths.
End of explanation
"""


cwd = os.getcwd()
fileName = 'example.csv'
filePath = os.path.join(cwd, fileName)

"""
Explanation: Step 2
Now lets create a variable, <code>filePath</code>, that is a string containing the full path to the file we want to import. The code below looks in the current working directory for the file given a file name input by the user. This isn't necessary, and is just included for convienence. Alternatively, user can input a full path into the <code>filePath</code> variable.
End of explanation
"""


df = pd.read_csv(filePath,header=0)
print(df)

"""
Explanation: Step 3
Great! Now lets read the data into a dataframe called <code>df</code>.
This will allow our data to be accessible by the string in the header.
End of explanation
"""


df['Time (s) - Dev1/ai0']

"""
Explanation: Our data is now accessible by a key value. The keys are the column headers in the dataframe. In this example case, those are 'Time (s) - Dev1/ai0' and  'Amplitude - Dev1/ai0'. For example, lets access the data in the first column.
End of explanation
"""


try:
    df[1]
except KeyError:
    print("KeyError: 1 - not a valid key")

"""
Explanation: What would happen if we tried to access the data with an invalid key, say <code>1</code> for example? Lets try it to find out.
Note: I enclose this code in a <code>try: except:</code> statement in order to prevent a huge error from being generated.
End of explanation
"""


cols = df.columns
for col in cols:
    print(df[col])

"""
Explanation: So lets say you have a large dataframe with unknown columns. There is a simple way to index them without having prior knowledge of what the dataframe columns are. Namely, the <code>columns</code> method in pandas.
End of explanation
"""


