Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

Python Pandas में जांचें कि DateTimeIndex में दिनांक लीप वर्ष से संबंधित है या नहीं

यह जांचने के लिए कि DateTimeIndex में दिनांक लीप वर्ष से संबंधित है या नहीं, DateTimeIndex.is_leap_year प्रॉपर्टी का उपयोग करें।

आवश्यक लाइब्रेरी आयात करें

import pandas as pd

DatetimeIndex बनाएं

पीरियड 6 और आवृत्ति Y यानी वर्ष के साथ DatetimeIndex बनाएं।

datetimeindex = pd.date_range('2021-12-30 02:30:50', periods=6, tz='Australia/Adelaide', freq='3Y')

DateTimeIndex प्रदर्शित करें

print("DateTimeIndex...\n", datetimeindex)

जांचें कि DateTimeIndex में दिनांक लीप वर्ष है या नहीं

print("\nCheck whether the date in DateTimeIndex belongs to a leap year or not...\n", datetimeindex.is_leap_year)

पूरा उदाहरण

import pandas as pd

# DatetimeIndex with period 6 and frequency as Y i.e. years
# The timezone is Australia/Adelaide
datetimeindex = pd.date_range('2021-12-30 02:30:50', periods=6, tz='Australia/Adelaide', freq='3Y')

# display DateTimeIndex
print("DateTimeIndex...\n", datetimeindex)

# display DateTimeIndex frequency
print("\nDateTimeIndex frequency...\n", datetimeindex.freq)

# Check whether the date in DateTimeIndex is a leap year or not
print("\nCheck whether the date in DateTimeIndex belongs to a leap year or not...\n", datetimeindex.is_leap_year)

आउटपुट

DateTimeIndex... DatetimeIndex(['2021-12-31 02:30:50+10:30', '2024-12-31 02:30:50+10:30', '2027-12-31 02:30:50+10:30', '2030-12-31 02:30:50+10:30', '2033-12-31 02:30:50+10:30', '2036-12-31 02:30:50+10:30'], dtype='datetime64[ns, Australia/Adelaide]', freq='3A-DEC')
DateTimeIndex frequency... <3 * YearEnds: month=12>
Check whether the date in DateTimeIndex belongs to a leap year or not... [False True False False False True]
  1. - Python Pandas - DateTimeIndex में महीने के पहले दिन की जांच करें

    Pandas में DateTimeIndex.is_month_start प्रॉपर्टी का उपयोग करके यह जांचा जा सकता है कि DateTimeIndex में दी गई तारीख महीने का पहला दिन है या नहीं। आवश्यक लाइब्रेरी इम्पोर्ट करें import pandas as pd DateTimeIndex बनाएं 6 पीरियड और 5 दिनों की फ्रीक्वेंसी के साथ DateTimeIndex बनाएं। टाइमज़ोन Australi

  1. - Python Pandas - DateTimeIndex से फ्रीक्वेंसी निकालें

    Pandas में DateTimeIndex से फ्रीक्वेंसी निकालने के लिए DateTimeIndex.freq प्रॉपर्टी का उपयोग करें। आवश्यक लाइब्रेरी इम्पोर्ट करें import pandas as pd DateTimeIndex बनाएं 6 पीरियड और दैनिक फ्रीक्वेंसी (D) के साथ DateTimeIndex बनाएं। टाइमज़ोन Australia/Adelaide पर सेट है। datetimeindex = pd.date_ran

  1. - पायथन पैंडास - पीरियड ऑब्जेक्ट से जांचें कि क्या वर्ष लीप वर्ष है

    पीरियड ऑब्जेक्ट से जांचने के लिए कि क्या वर्ष लीप वर्ष है, period.is_leap_year प्रॉपर्टी का उपयोग करें। सबसे पहले, आवश्यक लाइब्रेरी इंपोर्ट करें: import pandas as pd pandas.Period समय की अवधि को दर्शाता है। दो पीरियड ऑब्जेक्ट बनाएं: period1 = pd.Period(2020-09-23 05:55:30) period2 = pd.Period(freq=