<jupyter_start><jupyter_text>Exercise 1This exercise will be used to read in a file and setting logic to look for a specific pattern, in this case if the flight has used a dual sidestick input.- one file - sidestick_dual_input_altitude  Reading one file using the pandas librarySpecify the path via the variable within **''** to make it into a string.```pythonfilepath = '../data/raw/2018-03-04--00_9V-SSH_A-330-1648_SIA_0930__e9caf21c-df80-4eb0-a4f4-9bfdbf0c1e15.csv'```Calling the pandas method for reading a csv.```pythonpd.read_csv(filepath, delimiter=',')```<jupyter_code>import pandas as pd

# Specify the path via the variable within '' to make it into a string.
filepath = '../data/raw/2018-03-04--00_9V-SSH_A-330-1648_SIA_0930__e9caf21c-df80-4eb0-a4f4-9bfdbf0c1e15.csv'

# Calling the pandas method for reading a csv.
flight_df = pd.read_csv(filepath)<jupyter_output><empty_output><jupyter_text>For looping one of the columns of the read flightFrame and row comes from calling `iterrows` for the flight_df pandas object. This means that you are going through each row of the data in `row` and the frame is what row number. Meaning we loop through the frame number.```pythonfor frame, row in flight_df.iterrows():```Here we can access any column within the row by specifying `row['column_name']````python    if row['SIDESTICK_DUAL_INPUT_1'] == 1:```<jupyter_code>dual_input = 0
# Frame and row comes from calling iterrows for the flight_df pandas object. This means that you are going through each row of the data in row and the frame is what row number. Meaning we loop through the frame number.
for frame, row in flight_df.iterrows():
    
    # specify a varible to set for if the logic for that happens
    dual_1 = 0
    
    # Here we can access any column within the row by specifying row['column_name']
    if row['DUAL_SIDESTICK_INPUT_1'] == 1:
        dual_1 = 1
    
    # if we had a dual_1 input
    if dual_1 == 1:
        
        # set that dual input has happened
        dual_input = 1
        
        # setting the frame_number_at_sidestick_dual_input
        frame_number_at_sidestick_dual_input = frame
        
        # once the conditions are met within the for loop, we "break" the loop. Meaning we do not further go through the rows.
        break<jupyter_output><empty_output><jupyter_text>Defining a function to get the frame_numberDefining a function. This enables us to call the function multiple times instead of running the same code all the time.```pythondef get_dual_input_frame_number(csv_data):```For a function, we need to always return something from the function```pythonreturn frame_number_at_dual_used```<jupyter_code>def get_dual_input_frame_number(csv_data):

    dual_input = 0
    # Frame and row comes from calling iterrows for the flight_df pandas object. This means that you are going through each row of the data in row and the frame is what row number. Meaning we loop through the frame number.
    for frame, row in flight_df.iterrows():

        # specify a varible to set for if the logic for that happens
        dual_1 = 0

        # Here we can access any column within the row by specifying row['column_name']
        if row['DUAL_SIDESTICK_INPUT_1'] == 1:
            dual_1 = 1

        # if we had a dual_1 input
        if dual_1 == 1:

            # set that dual input has happened
            dual_input = 1

            # setting the frame_number_at_sidestick_dual_input
            frame_number_at_dual_used = frame

            # once the conditions are met within the for loop, we "break" the loop. Meaning we do not further go through the rows.
            break
            
    # specify the return of the function. This means that when you call the function; this variable will be sent back from it.
    return frame_number_at_dual_used<jupyter_output><empty_output><jupyter_text>Defining a function to getting the sidestick_dual_input_altitudeDefining a dictionary to be used for inputing values to save from the analysis```pythonoutput = {}```Calling the function get_dual_input_frame_number(csv_data)```pythonframe_number_at_dual_used = get_dual_input_frame_number(csv_data)```Getting the dual_input_altitude```pythonsidestick_dual_input_altitude = csv_data['ALTITUDE_STANDARD'][frame_number_at_dual_used]```<jupyter_code>def get_sidestick_dual_input_altitude(csv_data):
    
    # creating a dictionary {}
    output = {}
    
    # calling the function `get_dual_input_frame_number(csv_data)` to get frame_number 
    frame_number_at_dual_used = get_dual_input_frame_number(csv_data)
    
    # we use the frame_number_at_dual_used to use for the csv_data['ALTITUDE_STANDARD']
    # NOTE:
    # getting the column and row value
    # csv_data['column_name'][row_number]
    sidestick_dual_input_altitude = csv_data['ALTITUDE_STANDARD'][frame_number_at_dual_used]
        
        
    # save the frame_number key with the frame_number_at_dual_used - value
    output['frame_number_at_dual_used'] = frame_number_at_dual_used
    
    # save the sidestick_dual_input_altitude key with the sidestick_dual_input_altitude - value
    output['sidestick_dual_input_altitude'] = sidestick_dual_input_altitude
    
    return output
get_sidestick_dual_input_altitude(flight_df)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06510219530658592, 'fraction_numerical': 0.018357305071915214, 'mean_word_length': 3.9300373134328357, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '73172', 'license': 'MIT', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1596, 'n_words': 549, 'path': 'notebooks/exercise_1_dual_sidestick.ipynb', 'repo_name': 'eleijonmarck/python-training', 'size': '5284'}