Pandas DataFrame: to_dict() function
DataFrame - to_dict() function
The to_dict() function is used to convert the DataFrame to a dictionary.
Syntax:
DataFrame.to_dict(self, orient='dict', into=<class 'dict'>)
Parameters:
Name | Description | Type / Default Value | Required / Optional |
---|---|---|---|
orient | Determines the type of the values of the dictionary.
|
str {'dict', 'list', 'series', 'split', 'records', 'index'} | Required |
into | The collections.abc.Mapping subclass used for all Mappings in the return value. Can be the actual class or an empty instance of the mapping type you want. If you want a collections.defaultdict, you must pass it initialized. | class Default Value: dict |
Required |
Returns: dict, list or collections.abc.Mapping
Return a collections.abc.Mapping object representing the DataFrame. The resulting transformation depends on the orient parameter.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - to_sql() function
Next: DataFrame - to_excel() function
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook