w3resource

Pandas Series: dt.normalize() function

Series.dt.normalize() function

The dt.normalize() function is used to convert times to midnight.
The time component of the date-time is 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:

Series.dt.normalize(self, *args, **kwargs)
Pandas Series: dt.normalize() function

Returns: DatetimeArray, DatetimeIndex or Series
The same type as the original data. Series will have the same name and index. DatetimeIndex will have the same name.

Example:

Python-Pandas Code:

import numpy as np
import pandas as pd
idx = pd.date_range(start='2019-08-01 10:00', freq='H',
                    periods=3, tz='Asia/Calcutta')
idx

Output:

DatetimeIndex(['2019-08-01 10:00:00+05:30', '2019-08-01 11:00:00+05:30',
               '2019-08-01 12:00:00+05:30'],
              dtype='datetime64[ns, Asia/Calcutta]', freq='H')

Python-Pandas Code:

import numpy as np
import pandas as pd
idx = pd.date_range(start='2019-08-01 10:00', freq='H',
                    periods=3, tz='Asia/Calcutta')
idx.normalize()

Output:

DatetimeIndex(['2019-08-01 00:00:00+05:30', '2019-08-01 00:00:00+05:30',
               '2019-08-01 00:00:00+05:30'],
              dtype='datetime64[ns, Asia/Calcutta]', freq=None)

Previous: Series.dt.tz_convert() function
Next: Series.dt.strftime() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/pandas/series/series-dt-normalize.php