Python | Pandas DatetimeIndex.to_series() Last Updated : 29 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DatetimeIndex.to_series() function create a Series with both index and values equal to the index keys useful with map for returning an indexer based on an index. Syntax: DatetimeIndex.to_series(keep_tz=False, index=None, name=None) Parameters : keep_tz : return the data keeping the timezone index : index of resulting Series. If None, defaults to original index name : name of resulting Series. If None, defaults to name of original index Return : Series Example #1: Use DatetimeIndex.to_series() function to create a series object from the given DatetimeIndex object. Also set the value of index for the series. Python3 # importing pandas as pd import pandas as pd # Create the DatetimeIndex # Here 'S' represents secondly frequency didx = pd.DatetimeIndex(start ='2018-11-15 09:45:10', freq ='S', periods = 5) # Print the DatetimeIndex print(didx) Output : Now we want to construct a series out of the DatetimeIndex object. Python3 # construct the series didx.to_series(index =['A', 'B', 'C', 'D', 'E']) Output : As we can see in the output, the function has returned a series object constructed from the didx DatetimeIndex object. Example #2: Use DatetimeIndex.to_series() function to create a series object from the given DatetimeIndex object. Also set the value of index for the series. Python3 # importing pandas as pd import pandas as pd # Create the DatetimeIndex # Here 'M' represents monthly frequency didx = pd.DatetimeIndex(start ='2015-03-02', freq ='M', periods = 5) # Print the DatetimeIndex print(didx) Output : Now we want to construct a series out of the DatetimeIndex object. Python3 # construct the series didx.to_series(index =['First', 'Second', 'Third', 'Fourth', 'Fifth']) Output : As we can see in the output, the function has returned a series object constructed from the didx DatetimeIndex object. Comment More infoAdvertise with us Next Article Python | Pandas DatetimeIndex.to_series() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-datetimeIndex Practice Tags : python Similar Reads Python | Pandas DatetimeIndex.strftime() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DatetimeIndex.strftime() function convert to Index using specified date_format. 2 min read Python | Pandas DatetimeIndex.time Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DatetimeIndex.time attribute outputs an Index object containing the time values 2 min read Python | Pandas DatetimeIndex.year Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DatetimeIndex.year attribute outputs an Index object containing the value of ye 2 min read Python | Pandas DatetimeIndex.second Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DatetimeIndex.second attribute outputs an Index object containing the second va 2 min read Python | Pandas DatetimeIndex.round() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DatetimeIndex.round() function localize tz-naive DatetimeIndex to tz-aware Date 2 min read Like