विशिष्ट समय श्रृंखला आवृत्ति के साथ DateTimeIndex से दिनांक की तिमाही निकालने के लिए, DateTimeIndex. तिमाही का उपयोग करें ।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
एक डेटटाइम इंडेक्स बनाएं जिसमें अवधि 6 और आवृत्ति एम यानी माह के रूप में हो। समय क्षेत्र ऑस्ट्रेलिया/सिडनी है -
datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='2M')
प्रदर्शन दिनांक समय अनुक्रमणिका आवृत्ति -
print("DateTimeIndex frequency...\n", datetimeindex.freq)
तारीख की तिमाही पाएं -
print("\nGet the quarter of the date..\n",datetimeindex.quarter)
परिणाम एक वर्ष की निम्नलिखित तिमाहियों पर आधारित है -
Quarter 1 = 1st January to 31st March Quarter 2 = 1st April to 30th June Quarter 3 = 1st July to 30th September Quarter 4 = 1st October to 31st December
उदाहरण
निम्नलिखित कोड है -
import pandas as pd # DatetimeIndex with period 6 and frequency as M i.e. Month # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='2M') # display DateTimeIndex print("DateTimeIndex...\n", datetimeindex) # display DateTimeIndex frequency print("DateTimeIndex frequency...\n", datetimeindex.freq) # Get the quarter of the date # Result is based on the following quarters of an year: # Quarter 1 = 1st January to 31st March # Quarter 2 = 1st April to 30th June # Quarter 3 = 1st July to 30th September # Quarter 4 = 1st October to 31st December print("\nGet the quarter of the date..\n",datetimeindex.quarter)
आउटपुट
यह निम्नलिखित कोड उत्पन्न करेगा -
DateTimeIndex... DatetimeIndex(['2021-10-31 02:30:50+11:00', '2021-12-31 02:30:50+11:00', '2022-02-28 02:30:50+11:00', '2022-04-30 02:30:50+10:00', '2022-06-30 02:30:50+10:00', '2022-08-31 02:30:50+10:00'], dtype='datetime64[ns, Australia/Sydney]', freq='2M') DateTimeIndex frequency... <2 * MonthEnds> Get the quarter of the date.. Int64Index([4, 4, 1, 2, 2, 3], dtype='int64')