Can someone help me understand why python dictionary retain the original data order rather than taking the sorted data.
For Example here is a dataframe (df):
Id Date 0 AB001 12-03-2020 1 AB002 14-08-2023 2 AB003 16-08-2017 3 AB001 23-12-2023
Upon sorting the "Date" column to newest to oldest:
df.sort_values(['Date'],ascending=[False],inplace=True) Id Date1 AB001 2023-12-233 AB002 2023-08-140 AB001 2020-03-122 AB003 2017-08-16
When I map them using the below code
date_dict = dict(zip(df['Id'], df['Date']))
upon printing the value of Key ABOO1
--> the output is 2020-03-12
not 2023-12-23
.
why does this happen?