I am converting a pandas dataframe 'df' to dictionary using the command
df.to_dict( 'records')
Does this operation preserve the order of rows?
Yes, they do. Here are two dataframes:
DataFrame 1
Cat Vec
0 a [1, 2, 3]
1 a [4, 5, 6]
2 b [1, 2, 3]
Output:
[{'Cat': 'a', 'Vec': [1, 2, 3]},
{'Cat': 'a', 'Vec': [4, 5, 6]},
{'Cat': 'b', 'Vec': [1, 2, 3]}]
DataFrame 2
Cat Vec
0 a [1, 2, 3]
1 b [4, 5, 6]
2 a [1, 2, 3]
Output:
[{'Cat': 'a', 'Vec': [1, 2, 3]},
{'Cat': 'b', 'Vec': [4, 5, 6]},
{'Cat': 'a', 'Vec': [1, 2, 3]}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With