क्रमबद्ध CategoricalIndex से न्यूनतम मान प्राप्त करने के लिए, पैंडास में catIndex.min() विधि का उपयोग करें। सबसे पहले, आवश्यक लाइब्रेरी आयात करें:
import pandas as pd
categories पैरामीटर का उपयोग करके कैटेगोरिकल के लिए श्रेणियां सेट करें। ordered पैरामीटर का उपयोग करके कैटेगोरिकल को क्रमबद्ध मानें:
catIndex = pd.CategoricalIndex(
["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"]
)
कैटेगोरिकल इंडेक्स प्रदर्शित करें:
print("Categorical Index...\n", catIndex)
न्यूनतम मान प्राप्त करें:
print("\nMinimum value from CategoricalIndex...\n", catIndex.min())
उदाहरण
निम्नलिखित कोड है:
import pandas as pd
# CategoricalIndex अंतर्निहित कैटेगोरिकल पर आधारित इंडेक्स है
# "categories" पैरामीटर का उपयोग करके कैटेगोरिकल के लिए श्रेणियां सेट करें
# "ordered" पैरामीटर का उपयोग करके कैटेगोरिकल को क्रमबद्ध मानें
catIndex = pd.CategoricalIndex(
["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"]
)
# कैटेगोरिकल इंडेक्स प्रदर्शित करें
print("Categorical Index...\n", catIndex)
# श्रेणियां प्राप्त करें
print("\nDisplaying Categories from CategoricalIndex...\n", catIndex.categories)
# न्यूनतम मान प्राप्त करें
print("\nMinimum value from CategoricalIndex...\n", catIndex.min())
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा:
Categorical Index... CategoricalIndex(['p', 'q', 'r', 's', 'p', 'q', 'r', 's'], categories=['p', 'q', 'r', 's'], ordered=True, dtype='category') Displaying Categories from CategoricalIndex... Index(['p', 'q', 'r', 's'], dtype='object') Minimum value from CategoricalIndex... p