pandas   ||   4 lines, groupby, no merging    ||   T/S: 97% / 99%
Here\'s the plan\n1. We modify each timestamp, start or end, by multiplying that quantity by -2 or 2, respectively.\n2. We prune the unneeded columns and rename
Here\'s the plan\n1. We modify each timestamp, `start` or `end`, by multiplying that quantity by -2 or 2, respectively.\n2. We prune the unneeded columns and rename `timestamp` with`processing_time`.\n3. We we use `groupby` to compute the mean for each collection of modified times for each `machine_id`, and return the these results as a `pd.DataFrame`, rounded appropriately. (It\'s left to the interested reader with adequate beginning algebra skills to verify that this computation gives the appropriate answer) \n```\nimport pandas as pd\n\ndef get_average_time(activity: pd.DataFrame) -> pd.DataFrame:\n\n    activity.loc[activity[\'activity_type\'] == \'start\', \'timestamp\']*= -2    # <-- 1.\n    activity.loc[activity[\'activity_type\'] == \'end\'  , \'timestamp\']*=  2\n    \n    activity = activity.drop(columns = [\'activity_type\',  \'process_id\',]    # <-- 2.\n                    ).rename(columns = {\'timestamp\': \'processing_time\'})\n    \n    return activity.groupby(\'machine_id\').mean().round(3).reset_index()     # <-- 3.\n```\n[https://leetcode.com/problems/average-time-of-process-per-machine/submissions/1067181051/](https://leetcode.com/problems/average-time-of-process-per-machine/submissions/1067181051/)\n\nI could be wrong, but I think that time complexity is *O*(*MN*) and space complexity is *O*(*N*), in which *M* ~ `len(set(activity[\'machine_id\']))` and *N* ~ number of rows.
['Pandas']