หากต้องการคืนค่าดัชนีแบบโมโนโทนิก (เท่ากับหรือลดลงเท่านั้น) ให้ใช้ index.is_monotonic_decreasing ทรัพย์สิน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import pandas as pd
การสร้างดัชนี -
index = pd.Index([50, 40, 30, 30, 30])
แสดงดัชนี -
print("Pandas Index...\n",index) ตรวจสอบว่าดัชนี monotonic ลดลง −
print("\nIs the Pandas index monotonic decreasing?\n",index.is_monotonic_decreasing)
ตัวอย่าง
ต่อไปนี้เป็นรหัส -
import pandas as pd
# Creating the index
index = pd.Index([50, 40, 30, 30, 30])
# Display the index
print("Pandas Index...\n",index)
# Return an array representing the data in the Index
print("\nArray...\n",index.values)
# Check if the index monotonic decreasing
print("\nIs the Pandas index monotonic decreasing?\n",index.is_monotonic_decreasing) ผลลัพธ์
สิ่งนี้จะสร้างรหัสต่อไปนี้ -
Pandas Index... Int64Index([50, 40, 30, 30, 30], dtype='int64') Array... [50 40 30 30 30] Is the Pandas index monotonic decreasing? True