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