Python | Pandas DatetimeIndex.date



DatetimeIndex.date Pandas DatetimeIndex.date outputs an Index object containing the date values ​​present in each of the DatetimeIndex object records.

Syntax: DatetimeIndex.date

Return: numpy array of python datetime.date

Example # 1: Use the DatetimeIndex.date attribute to find the date portion of a DatetimeIndex object.

# import pandas as pd

import pandas as pd

 
# Create DatetimeIndex
# Here" W "represents the weekly frequency

didx = pd.DatetimeIndex (start = `2000-01-10 06:30` , freq = `W`

periods = 3 , tz = ` Asia / Calcutta` )

 
# Print DatetimeIndex

print (didx)

Output:

Now we want to find all date values ​​present in the DatetimeIndex object.

# find all date values ​​present in the object
didx.date

Output:

As we can see in the output, the function returned an Index object, containing the date values ​​present in each record of the DatetimeIndex object.

Example # 2: Use the DatetimeIndex.date attribute to find the date portion of the DatetimeIndex object.

# import pandas as pd

import pandas as pd

  
# Create DatetimeIndex
# Here "D" represents sets daily frequency

didx = pd. DatetimeIndex (start = `2014-08-01 10:05:45` , freq = ` D` ,

periods = 5 , tz = ` Asia / Calcutta` )

 
# Print DatetimeIndex

print (didx)

Output:

Now we want to find all the and the dates present in the DatetimeIndex object.

# find all date values ​​present in the object
didx.date

Output:

As we can see in the output, the function returned an Index object containing the date values ​​present in each object record DatetimeIndex.