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
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework