Python | Pandas DatetimeIndex.normalize()
Last Updated :
24 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.normalize()
function convert times to midnight. The time component of the date-timeise converted to midnight i.e. 00:00:00. This is useful in cases, when the time does not matter. Length is unaltered. The timezones are unaffected.
Syntax: DatetimeIndex.normalize()
Return: DatetimeIndex or Series
Example #1: Use DatetimeIndex.normalize()
function to normalize time.
import pandas as pd
idx = pd.DatetimeIndex(start = '2018-08-10 08:00' , freq = 'H' ,
periods = 5 , tz = 'Asia/Calcutta' )
print (didx)
|
Output :
Now we want all the time values present in the DatetimeIndex object to be normalized i.e., it gets converted to midnight time.
Output :
As we can see in the output, the function has converted all the time values in the object to midnight time.
Example #2: Use DatetimeIndex.normalize()
function to normalize time.
import pandas as pd
idx = pd.DatetimeIndex(start = '2000-01-15 08:00' , freq = 'Q' ,
periods = 4 , tz = 'Asia/Calcutta' )
print (didx)
|
Output :
Now we want all the time values present in the DatetimeIndex object to be normalized i.e., it gets converted to midnight time.
Output :
As we can see in the output, the function has converted all the time values in the object to midnight time.
Share your thoughts in the comments
Please Login to comment...