Pandas में DateTimeIndex.is_quarter_end प्रॉपर्टी का उपयोग करके यह जांचा जा सकता है कि DateTimeIndex में दी गई तारीख तिमाही का अंतिम दिन है या नहीं।
आवश्यक लाइब्रेरी इम्पोर्ट करें
import pandas as pd
DateTimeIndex बनाएं
6 पीरियड और 15 दिनों की फ्रीक्वेंसी के साथ DateTimeIndex बनाएं। टाइमज़ोन Australia/Adelaide पर सेट है।
datetimeindex = pd.date_range('2021-6-15 02:30:50', periods=6, tz='Australia/Adelaide', freq='15D')
DateTimeIndex प्रदर्शित करें
print("DateTimeIndex...\n", datetimeindex)
तिमाही के अंतिम दिन की जांच करें
print("\nCheck whether the date in DateTimeIndex is the last day of the quarter...\n", datetimeindex.is_quarter_end)
पूरा उदाहरण
import pandas as pd
# 6 पीरियड और 15 दिनों की फ्रीक्वेंसी के साथ DatetimeIndex
# टाइमज़ोन Australia/Adelaide
datetimeindex = pd.date_range('2021-6-15 02:30:50', periods=6, tz='Australia/Adelaide', freq='15D')
# DateTimeIndex प्रदर्शित करें
print("DateTimeIndex...\n", datetimeindex)
# DateTimeIndex फ्रीक्वेंसी प्रदर्शित करें
print("DateTimeIndex frequency...\n", datetimeindex.freq)
# तिमाही के अंतिम दिन की जांच करें
# परिणाम निम्नलिखित तिमाहियों पर आधारित है:
# तिमाही 1 = 1 जनवरी से 31 मार्च
# तिमाही 2 = 1 अप्रैल से 30 जून
# तिमाही 3 = 1 जुलाई से 30 सितंबर
# तिमाही 4 = 1 अक्टूबर से 31 दिसंबर
print("\nCheck whether the date in DateTimeIndex is the last day of the quarter...\n", datetimeindex.is_quarter_end)
आउटपुट
DateTimeIndex... DatetimeIndex(['2021-06-15 02:30:50+09:30', '2021-06-30 02:30:50+09:30', '2021-07-15 02:30:50+09:30', '2021-07-30 02:30:50+09:30', '2021-08-14 02:30:50+09:30', '2021-08-29 02:30:50+09:30'], dtype='datetime64[ns, Australia/Adelaide]', freq='15D')
DateTimeIndex frequency... <15 * Days>
Check whether the date in DateTimeIndex is the last day of the quarter... [False True False False False False]
व्याख्या: आउटपुट में दूसरा मान True है क्योंकि 30 जून दूसरी तिमाही (अप्रैल-जून) का अंतिम दिन है।