কম্পিউটার

Python Pandas - সময়কালকে পছন্দসই ফ্রিকোয়েন্সিতে রূপান্তর করুন


পিরিয়ডকে পছন্দসই ফ্রিকোয়েন্সিতে রূপান্তর করতে, period.asfreq() ব্যবহার করুন পদ্ধতি ধরা যাক আমরা 'H' স্পেসিফায়ার ব্যবহার করে কাঙ্খিত আওয়ারলি ফ্রিকোয়েন্সি সেট করব।

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

import pandas as pd

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

period1 = pd.Period("2020-09-23 03:15:40")
period2 = pd.Period(freq="D", year = 2021, month = 4, day = 16, hour = 2, minute = 35)

পিরিয়ড অবজেক্টগুলি প্রদর্শন করুন

print("Period1...\n", period1)
print("Period2...\n", period2)

সময়কালকে পছন্দসই ফ্রিকোয়েন্সিতে রূপান্তর করুন। আমরা ফ্রিকোয়েন্সি সেট করেছি H অর্থাৎ আওয়ারলি ফ্রিকোয়েন্সি

হিসেবে
res1 = period1.asfreq('H')
res2 = period2.asfreq('H')

উদাহরণ

নিচের কোড

import pandas as pd

# The pandas.Period represents a period of time
# creating two Period objects
period1 = pd.Period("2020-09-23 03:15:40")
period2 = pd.Period(freq="D", year = 2021, month = 4, day = 16, hour = 2, minute = 35)

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

# Convert Period to desired frequency
# We have set frequency as H i.e. Hourly frequency
res1 = period1.asfreq('H')
res2 = period2.asfreq('H')

# Return the year from the two Period objects
print("\nResult after conversion from the 1st Period object ...\n", res1)
print("\nResult after conversion from the 2nd Period object...\n", res2)

আউটপুট

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

Period1...
2020-09-23 03:15:40
Period2...
2021-04-16

Result after conversion from the 1st Period object ...
2020-09-23 03:00

Result after conversion from the 2nd Period object...
2021-04-16 23:00

  1. Python Pandas - প্রদত্ত টাইমস্ট্যাম্পকে সাপ্তাহিক ফ্রিকোয়েন্সি সহ পিরিয়ডে রূপান্তর করুন

  2. Python Pandas - প্রদত্ত টাইমস্ট্যাম্পকে মিনিটে ফ্রিকোয়েন্সি সহ পিরিয়ডে রূপান্তর করুন

  3. Python Pandas - প্রদত্ত টাইমস্ট্যাম্পকে পিরিয়ডে রূপান্তর করুন

  4. কিভাবে পান্ডা অফসেটকে পাইথন তারিখে রূপান্তর করবেন?