Để trả về nếu chỉ mục là các giá trị tăng đơn điệu (chỉ bằng hoặc tăng), hãy sử dụng index.is_monotonic_increasing tài sản.
Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd
Tạo chỉ mục -
index = pd.Index([10, 20, 20, 30, 40])
Hiển thị chỉ mục -
print("Pandas Index...\n",index) Kiểm tra xem chỉ số đơn điệu đang tăng -
print("\nIs the Pandas index monotonic increasing?\n",index.is_monotonic_increasing)
Ví dụ
Sau đây là mã -
import pandas as pd
# Creating the index
index = pd.Index([10, 20, 20, 30, 40])
# 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 increasing
print("\nIs the Pandas index monotonic increasing?\n",index.is_monotonic_increasing) Đầu ra
Điều này sẽ tạo ra mã sau -
Pandas Index... Int64Index([10, 20, 20, 30, 40], dtype='int64') Array... [10 20 20 30 40] Is the Pandas index monotonic increasing? True