Python | Pandas DatetimeIndex.to_frame() 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_frame() function create a DataFrame with a column containing the Index. By default the labels of the DatetimeIndex object is used as an index for the newly constructed Dataframe. Syntax: DatetimeIndex.to_frame(index=True) Parameters : index : Set the index of the returned DataFrame as the original Index Return : DataFrame containing the original Index data. Example #1: Use DatetimeIndex.to_frame() function to create a DataFrame object from the given DatetimeIndex object. Also set the index value to False 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 DataFrame out of the DatetimeIndex object. Python3 # construct the DataFrame didx.to_frame(index = False) Output : As we can see in the output, the function has returned a DataFrame object constructed from the didx DatetimeIndex object. Example #2: Use DatetimeIndex.to_frame() function to create a DataFrame object from the given DatetimeIndex object. 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 DataFrame out of the DatetimeIndex object. Python3 # construct the DataFrame didx.to_frame(index = True) Output : As we can see in the output, the function has returned a DataFrame object constructed from the didx DatetimeIndex object. Comment More infoAdvertise with us Next Article Python | Pandas DatetimeIndex.to_frame() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-datetimeIndex Practice Tags : python Similar Reads Python | Pandas DatetimeIndex.day 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.day attribute outputs an Index object containing the days in each 2 min read Python | Pandas DatetimeIndex.minute 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.minute attribute outputs an Index object containing the minute va 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.hour 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.hour attribute outputs an Index object containing the hour values 2 min read Python | Pandas DatetimeIndex.normalize() 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.normalize() function convert times to midnight. The time componen 2 min read Python | Pandas DatetimeIndex.tz_localize() 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.tz_localize() function localize tz-naive DatetimeIndex to tz-awar 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 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.to_period() 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_period() function is used to cast the given DatetimeIndex to P 2 min read Python | Pandas DatetimeIndex.to_series() 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 e 2 min read Like