Python | Pandas DatetimeIndex.to_period() Last Updated : 29 Dec, 2018 Summarize Comments Improve Suggest changes Share 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_period() function is used to cast the given DatetimeIndex to PeriodIndex at a particular frequency. The function basically converts DatetimeIndex to PeriodIndex. Syntax: DatetimeIndex.to_period(freq=None) Parameters : freq : One of pandas offset strings or an Offset object. Will be inferred by default Return : PeriodIndex Example #1: Use DatetimeIndex.to_period() function to cast the data of the DatetimeIndex object to PeriodIndex. 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 cast the DatetimeIndex object to PeriodIndex object. Python3 # cast to PeriodIndex # 'T' represents minute based frequency didx.to_period('T') Output : As we can see in the output, the function has casted the DatetimeIndex object to PeriodIndex object. Example #2: Use DatetimeIndex.to_period() function to cast the data of the DatetimeIndex object to PeriodIndex. Python3 # importing pandas as pd import pandas as pd # Create the DatetimeIndex # Here 'T' represents minutely frequency didx = pd.DatetimeIndex(start ='2015-03-02 01:15:12', freq ='T', periods = 5) # Print the DatetimeIndex print(didx) Output : Now we want to cast the DatetimeIndex object to PeriodIndex object. Python3 # cast to PeriodIndex # 'H' represents hourly frequency didx.to_period('H') Output : As we can see in the output, the function has casted the DatetimeIndex object to PeriodIndex object. Comment More infoAdvertise with us Next Article Python | Pandas DatetimeIndex.to_pydatetime() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-datetimeIndex Practice Tags : python Similar Reads Python | Pandas DatetimeIndex.to_perioddelta() 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_perioddelta() function calculate TimedeltaIndex of difference 2 min read Python | Pandas DatetimeIndex.to_pydatetime() 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_pydatetime() function return DatetimeIndex as object ndarray o 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.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.to_frame() 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 t 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 Like