Để kiểm tra xem chỉ mục có trống không với 0 phần tử hay không, hãy sử dụng index.empty tài sản ở Pandas.
Đầ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([])
Hiển thị chỉ mục -
print("Pandas Index...\n",index) Kiểm tra chỉ mục trống -
print("\nIs the index empty?\n",index.empty)
Ví dụ
Sau đây là mã -
import pandas as pd
# Creating the index
index = pd.Index([])
# Display the index
print("Pandas Index...\n",index)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)
# check for empty index
print("\nIs the index empty?\n",index.empty) Đầu ra
Điều này sẽ tạo ra mã sau -
Pandas Index... Index([], dtype='object') Number of elements in the index... 0 Is the index empty? True