pandas 1.4.2

ParametersReturnsBackRef
to_series(self, index=None, name: 'Hashable' = None) -> 'Series'

Useful with map for returning an indexer based on an index.

Parameters

index : Index, optional

Index of resulting Series. If None, defaults to original index.

name : str, optional

Name of resulting Series. If None, defaults to name of original index.

Returns

Series

The dtype will be based on the type of the Index values.

Create a Series with both index and values equal to the index keys.

See Also

Index.to_frame

Convert an Index to a DataFrame.

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')

By default, the original Index and original name is reused.

This example is valid syntax, but we were not able to check execution
>>> idx.to_series()
animal
Ant      Ant
Bear    Bear
Cow      Cow
Name: animal, dtype: object

To enforce a new Index, specify new labels to index :

This example is valid syntax, but we were not able to check execution
>>> idx.to_series(index=[0, 1, 2])
0     Ant
1    Bear
2     Cow
Name: animal, dtype: object

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_series(name='zoo')
animal
Ant      Ant
Bear    Bear
Cow      Cow
Name: zoo, dtype: object
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_frame

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#1512
type: <class 'function'>
Commit: