Company: KLA
Difficulty: medium
Problem Description Given a pandas DataFrame containing a dataset of taxi rides, write a Python function to find the longest ride by duration for each pickup month. Process the DataFrame according to the following rules: Drop all rows where the pickup_datetime or dropoff_datetime is missing (e.g., NaN or NaT). Calculate the duration of each ride, defined as the time difference between the dropoff and pickup times. Extract the pickup month from the pickup_datetime in the format YYYY-MM . Find the longest ride (maximum duration) for each pickup month. Sort the resulting DataFrame in ascending order by the pickup month. Input The input is a pandas DataFrame consisting of the following columns: id (string) : Unique trip identifier. vendor_id (integer) : Identifier for the taxi vendor. pickup_datetime (string or datetime) : The date and time when the ride started. dropoff_datetime (string or datetime) : The date and time when the ride ended. Output Return a pandas DataFrame with exactly two