ในการรับค่าต่ำสุดจาก Ordered CategoricalIndex ให้ใช้ catIndex.min() วิธีการในแพนด้า ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import pandas as pd
ตั้งค่าหมวดหมู่สำหรับหมวดหมู่โดยใช้พารามิเตอร์ "หมวดหมู่" ปฏิบัติต่อการจัดหมวดหมู่ตามคำสั่งโดยใช้พารามิเตอร์ "จัดลำดับ" -
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 is the Index based on an underlying Categorical
# Set the categories for the categorical using the "categories" parameter
# Treat the categorical as ordered using the "ordered" parameter
catIndex = pd.CategoricalIndex(
["p", "q", "r", "s","p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"]
)
# Display the Categorical Index
print("Categorical Index...\n",catIndex)
# Get the categories
print("\nDisplayingCategories from CategoricalIndex...\n",catIndex.categories)
# Get the min value
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') DisplayingCategories from CategoricalIndex... Index(['p', 'q', 'r', 's'], dtype='object') Minimum value from CategoricalIndex... P