📜  Python| Pandas Period.hour(1)

📅  最后修改于: 2023-12-03 14:46:22.755000             🧑  作者: Mango

Python | Pandas Period.hour

Pandas is a data manipulation library for Python. Pandas Period is used to represent a time span like a day, hour, minute, etc. Pandas Period.hour is used to represent a period of one hour.

Syntax
p = pd.Period('2019-09-01 22:00', freq='H')
Parameters
  • TimeStamp - A datetime object.
  • freq - Frequency of the period(hour, day, month, etc.)
Return Value
  • A Period object corresponding to the specified hour.
Examples
import pandas as pd

p = pd.Period('2019-09-01 22:00', freq='H')
print(p)

Output:

2019-09-01 22:00
import pandas as pd

p1 = pd.Period('2019-09-01 22:00', freq='H')
p2 = pd.Period('2019-09-01 23:00', freq='H')

diff = p2 - p1
print(diff)

Output:

1
Conclusion

Pandas Period.hour is a useful function for representing periods of one hour in Python. Pandas Period helps in dealing with time-series data and performing various operations on it.