pandas 1.4.2

ParametersReturnsBackRef
to_frame(self, index: 'bool' = True, name: 'Hashable' = <no_default>) -> 'DataFrame'

Parameters

index : bool, default True

Set the index of the returned DataFrame as the original Index.

name : object, default None

The passed name should substitute for the index name (if it has one).

Returns

DataFrame

DataFrame containing the original Index data.

Create a DataFrame with a column containing the Index.

See Also

Index.to_series

Convert an Index to a Series.

Series.to_frame

Convert Series to DataFrame.

Examples

This example is valid syntax, but we were not able to check execution
>>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal')
... idx.to_frame() animal animal Ant Ant Bear Bear Cow Cow

By default, the original Index is reused. To enforce a new Index:

This example is valid syntax, but we were not able to check execution
>>> idx.to_frame(index=False)
    animal
0   Ant
1  Bear
2   Cow

To override the name of the resulting column, specify :None:None:`name`:

This example is valid syntax, but we were not able to check execution
>>> idx.to_frame(index=False, name='zoo')
    zoo
0   Ant
1  Bear
2   Cow
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.indexes.base.Index.to_series

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/indexes/base.py#1575
type: <class 'function'>
Commit: