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
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/pandas/dataframe/dataframe-to_dict.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics