To turn a DataFrame into a Python dictionary, use df.to_dict(). This will return a dictionary whose keys are columns.
df.to_dict()
If you prefer to get a list of dictionaries whose elements are rows, use df.to_dict(orient='records') instead.
df.to_dict(orient='records')
Link to my previous tips on pandas.
DuckDB: Simplify DataFrame Analysis with Serverless SQL
Simplifying Dataset Comparison with Datacompy
Fuzzy Joining Tables with Non-Exact Matching Entries
Your email address will not be published. Required fields are marked *
Name
Email
Website
Save my name, email, and website in this browser for the next time I comment.
Δ