w3resource

Pandas: Create a yearly time period from a specified year and find the properties of this period


32. Yearly Time Period Properties

Write a Pandas program to create a yearly time period from a specified year and display the properties of this period.

Sample Solution:

Python Code :

import pandas as pd
ytp = pd.Period('2020','A-DEC')
print("Yearly time perid:",ytp)
print("\nAll the properties of the said period:")
print(dir(ytp))

Sample Output:

Yearly time perid: 2020

All the properties of the said period:
['__add__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__unicode__', '__weakref__', '_add_delta', '_from_ordinal', '_maybe_convert_freq', '_typ', 'asfreq', 'day', 'dayofweek', 'dayofyear', 'days_in_month', 'daysinmonth', 'end_time', 'freq', 'freqstr', 'hour', 'is_leap_year', 'minute', 'month', 'now', 'ordinal', 'quarter', 'qyear', 'second', 'start_time', 'strftime', 'to_timestamp', 'week', 'weekday', 'weekofyear', 'year']

For more Practice: Solve these Related Problems:

  • Write a Pandas program to create a yearly Period for a specified year and then display its start date, end date, and frequency.
  • Write a Pandas program to generate a yearly Period and then list its inherent properties, such as ordinal and frequency.
  • Write a Pandas program to construct a yearly Period from a given year and then validate its start, end, and duration against a standard calendar.
  • Write a Pandas program to create a yearly time period, extract its attributes, and compare them with the expected calendar year boundaries.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to create a monthly time period and display the list of names in the current local scope.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.