কম্পিউটার

Python Pandas - সময়কালের দিনের উপাদানের ঘন্টা পান


পিরিয়ডের দিনের উপাদানের ঘন্টা পেতে, period.hour ব্যবহার করুন সম্পত্তি।

প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -

import pandas as pd

পান্ডা. পিরিয়ড সময়কালের প্রতিনিধিত্ব করে। দুটি পিরিয়ড অবজেক্ট তৈরি করা -

period1 = pd.Period("2020-09-23 05:55:30")
period2 = pd.Period(freq="H", year = 2021, month = 7, day = 16, hour = 2, minute = 35)

দুটি পিরিয়ড অবজেক্ট −

থেকে দিনের ঘন্টা পান
res1 = period1.hour
res2 = period2.hour

উদাহরণ

নিম্নলিখিত কোড -

import pandas as pd

# The pandas.Period represents a period of time
# creating two Period objects
period1 = pd.Period("2020-09-23 05:55:30")
period2 = pd.Period(freq="H", year = 2021, month = 7, day = 16, hour = 2, minute = 35)

# display the Period objects
print("Period1...\n", period1)
print("Period2...\n", period2)

# get the hour of the day from two Period objects
res1 = period1.hour
res2 = period2.hour

# Return the hour of the day from the two Period objects
print("\nHour of the day from the 1st Period object ...\n", res1)
print("\nHour of the day from the 2nd Period object...\n", res2)

আউটপুট

এটি নিম্নলিখিত কোড তৈরি করবে -

Period1...
2020-09-23 05:55:30

Period2...
2021-07-16 02:00

Hour of the day from the 1st Period object ...
5

Hour of the day from the 2nd Period object...
2

  1. Python Pandas - প্রদত্ত পিরিয়ড অবজেক্টের ফ্রিকোয়েন্সি পান

  2. Python Pandas - পিরিয়ড অবজেক্ট থেকে বছরের দিন পান

  3. Python Pandas - পিরিয়ড যে সপ্তাহে আছে সেই সপ্তাহের দিন পান

  4. Python Pandas - মাসের যে দিনটি একটি পিরিয়ড পড়ে সেই দিনটি পান৷