Index.to_series()
Pandas Index.to_series()
creates a Series with index and values equal to index keys, which are used with map to return an index-based indexer. You can set a new index mark for a newly created series by passing in a list of new index marks.
Syntax: Index.to_series (index = None, name = None)
Parameters:
index: index of the resulting Series. If None, defaults to original index
name: name of the resulting Series. If None, defaults to name of original indexReturns: Series: dtype will be based on the type of the Index values.
Example # 1: Use Index.to_series ()
to convert an index to a Series.
|
Output:
Let’s convert the index to a series.
|
Output:
The function converted the index to a series. By default, the function creates a series index using the values of the original index.
Example # 2: Use Index.to_series ()
to convert the index to a series so that so that the created row uses the new index value.
|
Output:
Let’s convert the index to a series.
|
Output:
The function converted the index to a series. We have passed in a list of index marks to be used for the newly created series.