प्रति घंटा आवृत्ति के साथ DateTimeIndex पर फ्लोर ऑपरेशन करने के लिए, DateTimeIndex.floor() का उपयोग करें तरीका। घंटे की आवृत्ति के लिए, आवृत्ति . का उपयोग करें मान 'H' . के साथ पैरामीटर ।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
अवधि 5 के साथ एक डेटाटाइम इंडेक्स बनाएं और फ़्रीक्वेंसी न्यूनतम यानी मिनटों के रूप में -
datetimeindex = pd.date_range('2021-09-29 07:20:32.261811624', periods=5,
tz='Australia/Adelaide', freq='20min') डेटटाइमइंड प्रदर्शित करें -
print("DateTimeIndex...\n", datetimeindex) प्रति घंटा आवृत्ति के साथ DateTimeIndex तिथि पर तल संचालन, प्रति घंटा आवृत्ति के लिए, हमने 'H' का उपयोग किया है -
print("\nPerforming floor operation with hourly frequency...\n",
datetimeindex.floor(freq='H')) उदाहरण
निम्नलिखित कोड है -
import pandas as pd
# DatetimeIndex with period 5 and frequency as min i.e. minutes
# timezone is Australia/Adelaide
datetimeindex = pd.date_range('2021-09-29 07:20:32.261811624', periods=5,
tz='Australia/Adelaide', freq='20min')
# display DateTimeIndex
print("DateTimeIndex...\n", datetimeindex)
# display DateTimeIndex frequency
print("DateTimeIndex frequency...\n", datetimeindex.freq)
# Floor operation on DateTimeIndex date with hourly frequency
# For hourly frequency, we have used 'H'
print("\nPerforming floor operation with hourly frequency...\n",
datetimeindex.floor(freq='H')) का उपयोग किया है आउटपुट
यह निम्नलिखित कोड उत्पन्न करेगा -
DateTimeIndex... DatetimeIndex(['2021-09-29 07:20:32.261811624+09:30', '2021-09-29 07:40:32.261811624+09:30', '2021-09-29 08:00:32.261811624+09:30', '2021-09-29 08:20:32.261811624+09:30', '2021-09-29 08:40:32.261811624+09:30'], dtype='datetime64[ns, Australia/Adelaide]', freq='20T') DateTimeIndex frequency... <20 * Minutes> Performing floor operation with hourly frequency... DatetimeIndex(['2021-09-29 07:00:00+09:30', '2021-09-29 07:00:00+09:30', '2021-09-29 08:00:00+09:30', '2021-09-29 08:00:00+09:30', '2021-09-29 08:00:00+09:30'], dtype='datetime64[ns, Australia/Adelaide]', freq=None)