I'm trying to group my df by a column named "id", my code is working my only problem is that my grouped_df return number (e.g., 43248 or 43249) in the "created_date" and in the "date" column instead of the actual original date. This is my code:
unique_df['created_date'] = pd.to_datetime(unique_df['created_date'], format='%Y-%m-%d')
unique_df['date'] = pd.to_datetime(unique_df['date'], format='%Y-%m-%d')
aggregations = {
'username': 'first',
'created_date': 'first',
'id': 'count',
'date': ['first', 'last'],
'like_count': 'sum',
'list_count': ['first', 'last']
}
grouped_df = unique_df.groupby('id').agg(aggregations)
grouped_df['created_date'] = pd.to_datetime(grouped_df['created_date'], format='%Y-%m-%d')
grouped_df['date_first'] = pd.to_datetime(grouped_df['date_first'], format='%Y-%m-%d')
grouped_df['date_last'] = pd.to_datetime(grouped_df['date_last'], format='%Y-%m-%d')
How can I keep the original date format and avoid having number instead of date?