Pandas solution using Groupby
Approach\n Describe your approach to solving the problem. \n1. After analysing the output, we can conclude that the data has been grouped by \'event_day\' as we
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. After analysing the output, we can conclude that the data has been grouped by \'event_day\' as well as \'emp_id\'. So we apply group by operation first.\n2. Then we select both \'in_time\' and \'out_time\' columns and sum those columns.\n3. Now we create a new column \'total_time\' that is a simple difference between above 2 columns.\n4. Then we kind of drop unwanted columns, keeping only the information asked in the output table.\n5. Finally we rename 1 pending column \'event_day\' to \'day\' and return the DataFrame\n\n\n# Code\n```\nimport pandas as pd\n\ndef total_time(employees: pd.DataFrame) -> pd.DataFrame:\n    # Group by \'event_day\' and \'emp_id\' columns, sum columns \'in_time\' and \'out_time\'\n    grouped_df = employees.groupby([\'event_day\',\'emp_id\'])[[\'in_time\',\'out_time\']].sum().reset_index()\n\n    # create column \'total_time\'\n    grouped_df[\'total_time\'] = grouped_df[\'out_time\'] - grouped_df[\'in_time\']\n\n    # only select columns required in output\n    grouped_df = grouped_df[[\'event_day\',\'emp_id\',\'total_time\']]\n\n    # rename col \'event_day\' to match output col \'day\'\n    grouped_df.rename(columns={\'event_day\': \'day\'}, inplace=True)\n\n    return grouped_df\n```
['Pandas']