Python - 檢查包含某些 NaN 的 Pandas 索引是否為浮點型別
要檢查包含某些 NaN 的 Pandas 索引是否為浮點型別,請使用 **index.is_floating()** 方法。首先,匯入所需的庫 −
import pandas as pd import numpy as np
建立包含某些 NaN 的 Pandas 索引 −
index = pd.Index([5.7, 6.8, 10.5, np.nan,17.8, 25.6, np.nan ,np.nan, 50.2])
顯示 Pandas 索引 −
print("Pandas Index...\n",index)檢查包含某些 NaN 的索引值是否為浮點型別 −
print("\nIndex values with some NaNs is a floating type?\n",index.is_floating())示例
以下為程式碼 −
import pandas as pd
import numpy as np
# Creating Pandas index with some NaNs
index = pd.Index([5.7, 6.8, 10.5, np.nan,17.8, 25.6, np.nan ,np.nan, 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 with some NaNs are floating type
print("\nIndex values with some NaNs is a floating type?\n",index.is_floating())輸出
這將生成以下輸出 −
Pandas Index... Float64Index([5.7, 6.8, 10.5, nan, 17.8, 25.6, nan, nan, 50.2], dtype='float64') Number of elements in the index... 9 The dtype object... float64 Index values with some NaNs is a floating type? True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式語言
C++
C#
MongoDB
MySQL
Javascript
PHP