Python | Pandas DatetimeIndex.to_pydatetime() 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_pydatetime() function return DatetimeIndex as object ndarray of datetime.datetime objects. The function does not take any input value. Syntax: DatetimeIndex.to_pydatetime() Parameters : None Return : ndarray Example #1: Use DatetimeIndex.to_pydatetime() function to convert the DatetimeIndex as object ndarray of datetime.datetime objects. 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 convert the DatetimeIndex to datetime.datetime objects. Python3 # convert to datetime.datetime objects. didx.to_pydatetime() Output : As we can see in the output, the function has converted the DatetimeIndex object to python datetime.datetime object. Example #2: Use DatetimeIndex.to_pydatetime() function to convert the DatetimeIndex as object ndarray of datetime.datetime objects. 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 convert the DatetimeIndex to datetime.datetime objects. Python3 # convert to datetime.datetime objects. didx.to_pydatetime() Output : As we can see in the output, the function has converted the DatetimeIndex object to python datetime.datetime 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_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_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.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.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.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.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.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 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.to_datetime() When a CSV file is imported and a Data Frame is made, the Date time objects in the file are read as a string object rather than a Date Time object Hence itâs very tough to perform operations like Time difference on a string rather than a Date Time object. Pandas to_datetime() method helps to convert 4 min read Pandas Series dt.to_pydatetime | Return Python DateTime Objects Pandas dt.to_pydatetime() method returns the data as an array of native Python DateTime objects. Timezone information is retained if present. Example Python3 import pandas as pd sr = pd.Series(['2012-12-31', '2019-1-1 12:30', '2008-02-2 10:30', '2010-1-1 09:25', '2019-12-31 00:00']) idx = ['Day 1', 2 min read Like