+

Python | Pandas PeriodIndex.dayofyear

PeriodIndex.dayofyear Pandas PeriodIndex.dayofyear returns an Index object. The index contains the ordinal day of the year for each element in this PeriodIndex object.

Syntax: PeriodIndex.dayofyear

Parameters: None

Return: Index

Example # 1: Use the PeriodIndex.dayofyear attribute to find the value of the ordinal days of the year for each element in a given PeriodIndex object.

# import pandas as pd

import pandas as pd

 
# Create PeriodIndex object

pidx = pd.PeriodIndex (start = `2005-12-21`

end = `2005-12-29` , freq = ` D` )

 
# Print PeriodIndex object

print (pidx)

Output:

We will now use the PeriodIndex.dayofyear attribute to find the value of the ordinal days of the year for each item in a given object.

# return the value of the sequence number
# days in a year
pidx.dayofyear

Output:

As we can see from output, the PeriodIndex.dayofyear attribute returned an Index object containing the value of the ordinal days of the year for each item in this PeriodIndex object.

Example # 2: Use the PeriodIndex.dayofyear attribute to find the value of the ordinal days of the year for each item in a given PeriodIndex object.

# import pandas as pd

import pandas as pd

 
# Create PeriodIndex object

pidx = < / code> pd.PeriodIndex (start = `2011-03-14`

end = `2011-03-21` , freq = ` D` )

  
# Print PeriodIndex object

print (pidx)

Output:

Now we will use the PeriodIndex.dayofyear attribute to find the value of the ordinal days of the year for each element in this object.

# return the value of the sequence number
# days in a year
pidx.dayofyear

Output:

As we can see from the output, the PeriodIndex.dayofyear attribute returned an Index object containing the value of the ordinal days of the year for each item in this PeriodIndex object.

Get Solution for free from DataCamp guru