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

पायथन पैंडास - दिए गए लेबल के अनुरूप राइट स्लाइस बाउंड की गणना करें


दिए गए लेबल के अनुरूप राइट स्लाइस बाउंड की गणना करने के लिए, index.get_slice_bound() का उपयोग करें। side पैरामीटर को right पर सेट करें।

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

import pandas as pd

पैंडास इंडेक्स बनाएं:

index = pd.Index([10, 20, 30, 40, 50, 60, 70])

पैंडास इंडेक्स प्रदर्शित करें:

print("Pandas Index...\n", index)

राइट स्लाइस बाउंड प्राप्त करें। यदि "side" पैरामीटर "right" पर सेट है तो दिए गए लेबल का राइट स्लाइस बाउंड लौटाता है:

print("\nGet the right slice bound...\n", index.get_slice_bound(30, side='right', kind='getitem'))

उदाहरण

import pandas as pd
# Creating Pandas index
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
# Display the Pandas index
print("Pandas Index...\n", index)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n", index.size)
# Get the right slice bound
# Returns the right slice bound of given label if "side" parameter is set to "right"
print("\nGet the right slice bound...\n", index.get_slice_bound(30, side='right', kind='getitem'))

आउटपुट

Pandas Index... Int64Index([10, 20, 30, 40, 50, 60, 70], dtype='int64')
Number of elements in the index... 7
Get the right slice bound... 3
  1. - पायथन - जांचें कि पैंडास इंडेक्स फ्लोटिंग टाइप का है या नहीं

    जांचने के लिए कि पैंडास इंडेक्स फ्लोटिंग टाइप का है या नहीं, पैंडास में index.is_floating() मेथड का उपयोग करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें: import pandas as pd पैंडास इंडेक्स बनाएं: index = pd.Index([5.7, 6.8, 10.5, 20.4, 25.6, 30.8, 40.5, 50.2]) पैंडास इंडेक्स प्रदर्शित करें: print(Pa

  1. - पायथन पैंडास - IntervalArray में प्रत्येक इंटरवल के बाएं एंडपॉइंट्स इंडेक्स के रूप में लौटाएं

    IntervalArray में प्रत्येक इंटरवल के बाएं एंडपॉइंट्स इंडेक्स के रूप में लौटाने के लिए array.left प्रॉपर्टी का उपयोग करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें: import pandas as pd दो इंटरवल ऑब्जेक्ट बनाएं: interval1 = pd.Interval(10, 25) interval2 = pd.Interval(15, 70) इंटरवल्स प्रदर्शित करें: p

  1. - पायथन पैंडास - जांचें कि खुले एंडपॉइंट साझा करने वाले दो इंटरवल ऑब्जेक्ट्स ओवरलैप करते हैं या नहीं

    जांचने के लिए कि खुले एंडपॉइंट साझा करने वाले दो इंटरवल ऑब्जेक्ट्स ओवरलैप करते हैं या नहीं, overlaps() मेथड का उपयोग करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें: import pandas as pd दो इंटरवल ओवरलैप करते हैं यदि वे एक सामान्य बिंदु साझा करते हैं, जिसमें क्लोज्ड एंडपॉइंट्स शामिल हैं। इंटरवल्स जो क