Pandas step-by-step solution | Beats 100%
Intuition\n1. Renaming a column from \'event_day\' to \'day\'\n.rename(columns={\'event_day\':\'day\'})\n\n2. Creating a new column \'total_time\' that is fille
# Intuition\n1. Renaming a column from \'event_day\' to \'day\'\n```.rename(columns={\'event_day\':\'day\'})```\n\n2. Creating a new column \'total_time\' that is filled with a difference \'out_time\' \u0438 \'in_time\' using the method assign(), which is equivalent:\n```employees[\'total_time\'] = employees[\'out_time\'] - employees[\'in_time\']```\n```.assign(total_time=employees[\'out_time\'] - employees[\'in_time\'])```\n\n3. Concatenation of strings for each combination of date + emp_id\n```.groupby([\'day\', \'emp_id\'])```\n\n4. Sums the value of the \'total_time\' for each group\n```[\'total_time\'].sum()```\n\n5. Reset index for translation back in DataFrame instead of object of type GroupBy\n```.reset_index()```\n\n# Memory\n61.96 mb\nBeats 81.82% of users with Pandas\n\n# Runtime\n299 ms\nBeats 100.00% of users with Pandas\n\n# Code\n```\nimport pandas as pd\n\ndef total_time(employees: pd.DataFrame) -> pd.DataFrame:\n    return (\n        employees\n        .rename(columns={\'event_day\':\'day\'})\n        .assign(total_time=employees[\'out_time\'] - employees[\'in_time\'])\n        .groupby([\'day\', \'emp_id\'])[\'total_time\'].sum()\n        .reset_index()\n        )\n```
['Pandas']