Python | Pandas DatetimeIndex.to_pydatetime()
Last Updated :
29 Dec, 2018
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.
import pandas as pd
didx = pd.DatetimeIndex(start = '2018-11-15 09:45:10' , freq = 'S' , periods = 5 )
print (didx)
|
Output :
Now we want to convert the DatetimeIndex to datetime.datetime objects.
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.
import pandas as pd
didx = pd.DatetimeIndex(start = '2015-03-02' , freq = 'M' , periods = 5 )
print (didx)
|
Output :
Now we want to convert the DatetimeIndex to datetime.datetime objects.
Output :
As we can see in the output, the function has converted the DatetimeIndex object to python datetime.datetime object.
Share your thoughts in the comments
Please Login to comment...