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

पायथन पैंडास - उस महीने के कुल दिन प्राप्त करें जिसमें पीरियड आता है


उस महीने के कुल दिन प्राप्त करने के लिए जिसमें एक पीरियड आता है, period.daysinmonth प्रॉपर्टी का उपयोग करें।

सबसे पहले, आवश्यक लाइब्रेरी इंपोर्ट करें:

import pandas as pd

pandas.Period समय की अवधि को दर्शाता है। दो पीरियड ऑब्जेक्ट बनाएं:

period1 = pd.Period("2020-09-23")
period2 = pd.Period(freq="D", year=2021, month=2, day=14, hour=2, minute=35)

पीरियड ऑब्जेक्ट्स प्रदर्शित करें:

print("Period1...\n", period1)
print("Period2...\n", period2)

दो पीरियड ऑब्जेक्ट्स से महीने के दिन प्राप्त करें:

res1 = period1.daysinmonth
res2 = period2.daysinmonth

उदाहरण

import pandas as pd
# The pandas.Period represents a period of time
# creating two Period objects
period1 = pd.Period("2020-09-23")
period2 = pd.Period(freq="D", year=2021, month=2, day=14, hour=2, minute=35)
# display the Period objects
print("Period1...\n", period1)
print("Period2...\n", period2)
# get the days in the month from two Period objects
res1 = period1.daysinmonth
res2 = period2.daysinmonth
# Return the days in the month from two Period objects
print("\nReturn Days in the month from the 1st Period object ...\n", res1)
print("\nReturn Days in the month from the 2nd Period object ...\n", res2)

आउटपुट

Period1... 2020-09-23
Period2... 2021-02-14
Return Days in the month from the 1st Period object ... 30
Return Days in the month from the 2nd Period object ... 28
  1. - पायथन पैंडास - टाइमडेल्टा से दिनों की संख्या प्राप्त करें

    पैंडास में टाइमडेल्टा से दिनों की संख्या प्राप्त करने के लिए timedelta.days प्रॉपर्टी का उपयोग करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें: import pandas as pd पायथन का स्टैंडर्ड datetime लाइब्रेरी टाइमडेल्टा के लिए अलग प्रतिनिधित्व उपयोग करता है। टाइमडेल्टा ऑब्जेक्ट बनाएं: timedelta = pd.Timedel

  1. - Python में महीने में दिनों की संख्या

    मान लीजिए हमारे पास एक वर्ष Y और एक महीना M है, हमें दिए गए वर्ष के लिए उस महीने के दिनों की संख्या लौटानी है। इसलिए यदि Y = 1992 और M = 7, तो परिणाम 31 होगा, यदि वर्ष 2020 है, और M = 2, तो परिणाम 29 है। इसे हल करने के लिए, हम इन चरणों का पालन करेंगे - यदि m = 2, तो यदि y लीप वर्ष है, तो 29 लौटाएं,

  1. - Python में रेंज के भीतर वर्षों में कुल लीप डेज कैसे प्राप्त करें?

    Python कैलेंडर लाइब्रेरी में रेंज के भीतर वर्षों में कुल लीप डेज खोजने के लिए एक फंक्शन है। calender.leapdays(y1, y2) रेंज(y1,y2) के भीतर वर्षों में कुल लीप डेज लौटाता है। उदाहरण के लिए import calendar print(calendar.leapdays(1995, 2018)) आउटपुट यह आउटपुट देगा: 6