Python - 檢查 Pandas 索引是否為浮點型別
要檢查 Pandas 索引是否為浮點型別,請在 Pandas 中使用 index.is_floating() 方法。首先,匯入所需的程式碼庫 -
import pandas as pd
建立 Pandas 索引 −
index = pd.Index([5.7, 6.8, 10.5, 20.4, 25.6, 30.8, 40.5, 50.2])
顯示 Pandas 索引 −
print("Pandas Index...\n",index)檢查索引值是否僅包含浮點數 −
print("\nIndex values only consists of floats?\n",index.is_floating())示例
以下是程式碼 −
import pandas as pd
# Creating Pandas index
index = pd.Index([5.7, 6.8, 10.5, 20.4, 25.6, 30.8, 40.5, 50.2])
# Display the Pandas index
print("Pandas Index...\n",index)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)
# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)
# check whether index values has only floats
print("\nIndex values only consists of floats?\n",index.is_floating())輸出
這將產生以下輸出 −
Pandas Index... Float64Index([5.7, 6.8, 10.5, 20.4, 25.6, 30.8, 40.5, 50.2], dtype='float64') Number of elements in the index... 8 The dtype object... float64 Index values only consists of floats? True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP