From 6ea1855489f5b1cc885ba1163451ccb717686ceb Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Date: Sun, 24 May 2020 15:51:00 +0700 Subject: [PATCH] DOC: Fix error in pandas.Index.to_series --- pandas/core/indexes/base.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 1cf319a11766d..fb266b4abba51 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1037,13 +1037,48 @@ def to_series(self, index=None, name=None): index : Index, optional Index of resulting Series. If None, defaults to original index. name : str, optional - Dame of resulting Series. If None, defaults to name of original + 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. + + See Also + -------- + Index.to_frame : Convert an Index to a DataFrame. + Series.to_frame : Convert Series to DataFrame. + + Examples + -------- + >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') + + By default, the original Index and original name is reused. + + >>> idx.to_series() + animal + Ant Ant + Bear Bear + Cow Cow + Name: animal, dtype: object + + To enforce a new Index, specify new labels to ``index``: + + >>> 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 `name`: + + >>> idx.to_series(name='zoo') + animal + Ant Ant + Bear Bear + Cow Cow + Name: zoo, dtype: object """ from pandas import Series