Python - 在 Pandas 索引中显示条目为 NA 的内容
若要显示 Pandas 索引中哪些条目为 NA,请在 Pandas 中使用 index.isna()。首先,导入所需的库 -
import pandas as pd import numpy as np
创建带有某些 NaN 值的 Pandas 索引 -
index = pd.Index([5, 65, np.nan, 17, 75, np.nan])
显示 Pandas 索引 -
print("Pandas Index...\n",index)显示 Pandas 索引中哪些条目为 NA。对于 NA 条目返回 True -
print("\nCheck which entries are NA...\n", index.isna())
示例
以下是代码 -
import pandas as pd
import numpy as np
# Creating Pandas index with some NaN values
index = pd.Index([5, 65, np.nan, 17, 75, np.nan])
# 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)
# Show which entries in a Pandas index are NA
# Return True for NA entries
print("\nCheck which entries are NA...\n", index.isna())输出
将生成以下输出 -
Pandas Index... Float64Index([5.0, 65.0, nan, 17.0, 75.0, nan], dtype='float64') Number of elements in the index... 6 The dtype object... float64 Check which entries are NA... [False False True False False True]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP