<jupyter_start><jupyter_text>HW3 - Q3 [35 pts]  Important Notices    WARNING: REMOVE any print statements added to cells with "export" that are used for debugging purposes befrore submitting because they will crash the autograder in Gradescope. Any additional cells can be used for testing purposes at the bottom.     WARNING: Do NOT remove any comment that says "export" because that will crash the autograder in Gradescope. We use this comment to export your code in these cells for grading.    WARNING: Do NOT import any additional libraries into this workbook.All instructions, code comments, etc. in this notebook **are part of the assignment instructions**. That is, if there is instructions about completing a task in this notebook, that task is not optional.      You must implement the following functions in this notebook to receive credit.`user()``long_trips()``manhattan_trips()``weighted_profit()``final_output()`Each method will be auto-graded using different sets of parameters or data, to ensure that values are not hard-coded.  You may assume we will only use your code to work with data from the NYC-TLC dataset during auto-grading.    WARNING: Do NOT remove or modify the following utility functions:`load_data()``main()`     Do not change the below cell. Run it to initialize your PySpark instance. If you don't get any output, make sure your Notebook's Kernel is set to "PySpark" in the top right corner.<jupyter_code>sc<jupyter_output><empty_output><jupyter_text>WARNING: Do NOT remodify the below cell. It contains the function for loading data and all imports, and the function for running your code.<jupyter_code>#export
from pyspark.sql.functions import col
from pyspark.sql import *
#### DO NOT CHANGE ANYTHING IN THIS CELL ####

def load_data(size='small'):
    # Loads the data for this question. Do not change this function.
    # This function should only be called with the parameter 'small' or 'large'
    
    if size != 'small' and size != 'large':
        print("Invalid size parameter provided. Use only 'small' or 'large'.")
        return
    
    input_bucket = "s3://cse6242-hw3-q3"
    
    # Load Trip Data
    trip_path = '/'+size+'/yellow_tripdata*'
    trips = spark.read.csv(input_bucket + trip_path, header=True, inferSchema=True)
    print("Trip Count: ",trips.count()) # Prints # of trips (# of records, as each record is one trip)
    
    # Load Lookup Data
    lookup_path = '/'+size+'/taxi*'
    lookup = spark.read.csv(input_bucket + lookup_path, header=True, inferSchema=True)
    
    return trips, lookup

def main(size, bucket):
    # Runs your functions implemented above.
    
    print(user())
    trips, lookup = load_data(size=size)
    trips = long_trips(trips)
    mtrips = manhattan_trips(trips, lookup)
    wp = weighted_profit(trips, mtrips)
    final = final_output(wp, lookup)
    
    # Outputs the results for you to visually see
    final.show()
    
    # Writes out as a CSV to your bucket.
    final.write.csv(bucket)<jupyter_output><empty_output><jupyter_text>Implement the below functions for this assignment:    WARNING: Do NOT change any function inputs or outputs, and ensure that the dataframes your code returns align with the schema definitions commented in each function. Do NOT remove the export comment from each of the code blocks either. This can prevent your code from being converted to a python file.  3a. [1 pt] Update the `user()` functionThis function should return your GT username, eg: gburdell3<jupyter_code>#export
def user():
    # Returns a string consisting of your GT username.
    return 'gburdell3'<jupyter_output><empty_output><jupyter_text>3b. [2 pts] Update the `long_trips()` functionThis function filters trips to keep only trips greater than or equal to 2 miles.<jupyter_code>#export
def long_trips(trips):
    # Returns a Dataframe (trips) with Schema the same as :trips:
    pass<jupyter_output><empty_output><jupyter_text>3c. [6 pts] Update the `manhattan_trips()` functionThis function determines the top 20 locations with a `DOLocationID` in manhattan by passenger_count (pcount).Example output formatting:```+--------------+--------+| DOLocationID | pcount |+--------------+--------+|             5|      15||            16|      12| +--------------+--------+```<jupyter_code>#export
def manhattan_trips(trips, lookup):
    # Returns a Dataframe (mtrips) with Schema: DOLocationID, pcount
    pass<jupyter_output><empty_output><jupyter_text>3d. [6 pts] Update the `weighted_profit()` functionThis function should determine the average `total_amount`, the total count of trips, and the total count of trips ending in the top 20 destinations and return the `weighted_profit` as discussed in the homework document.Example output formatting:```+--------------+-------------------+| PULocationID |  weighted_profit  |+--------------+-------------------+|            18| 33.784444421924436| |            12| 21.124577637149223| +--------------+-------------------+```<jupyter_code>#export
def weighted_profit(trips, mtrips): 
    # Returns a Dataframe (wp) with Schema: PULocationID, weighted_profit
    # Note: Use decimal datatype for weighted profit (NOTE: DON'T USE FLOAT)
    # Our grader will be only be checking the first 8 characters for each value in the dataframe
    pass<jupyter_output><empty_output><jupyter_text>3e. [5 pts] Update the `final_output()` functionThis function will take the results of `weighted_profit`, links it to the `borough` and `zone` and returns the top 20 locations with the highest `weighted_profit`.Example output formatting:```+------------+---------+-------------------+|    Zone    | Borough |  weighted_profit  |+----------------------+-------------------+| JFK Airport|   Queens|  16.95897820117925||     Jamaica|   Queens| 14.879835188762488|+------------+---------+-------------------+```<jupyter_code>#export
def final_output(wp, lookup): 
    # Returns a Dataframe (final) with Schema: Zone, Borough, weighted_profit
    # Note: Use decimal datatype for weighted profit (NOTE: DON'T USE FLOAT)
    # Our grader will be only be checking the first 8 characters for each value in the dataframe
    pass<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12669683257918551, 'fraction_numerical': 0.01777634130575307, 'mean_word_length': 3.427038626609442, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '437727', 'license': 'MIT', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1688, 'n_words': 694, 'path': 'Q3/q3.ipynb', 'repo_name': 'garbamoussa/Pyspark', 'size': '6188'}