I am leveraging the function .to_dicts() in my testing the resulting list of dictionaries has the same order as the dataframe.
df = pl.DataFrame(data={
"name": ["Alice", "Bob", "Charlie"],
"age": [30, 25, 35],
"city": ["New York", "London", "Paris"],
}).sort(by=['name'], descending=True)
data = df.to_dicts()
for record in data:
print(record)
Results in:
{'name': 'Charlie', 'age': 35, 'city': 'Paris'}
{'name': 'Bob', 'age': 25, 'city': 'London'}
{'name': 'Alice', 'age': 30, 'city': 'New York'}
Does anyone know if that is guaranteed to happen every time?
TLDR. Yes.
This can be seen by inspecting this underlying rust function, which maps over the indices of the DataFrame in order.
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