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