Python – 显示Pandas Index中的哪些条目是NA

Python – 显示Pandas Index中的哪些条目是NA

要显示Pandas Index中哪些条目是NA,请在Pandas中使用 index.isna() 。首先,导入所需的库 –

import pandas as pd
import numpy as np

创建带有一些NaN值的Pandas Index −

index = pd.Index([5, 65, np.nan, 17, 75, np.nan])

显示Pandas Index −

print("Pandas Index...\n",index)

显示Pandas Index中的哪些条目是NA。返回True用于NA条目−

print("\n检查哪些条目是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("\n索引中元素的数量...\n",index.size)

# Return the dtype of the data
print("\n数据的dtype对象...\n",index.dtype)

# Show which entries in a Pandas index are NA
# Return True for NA entries
print("\n检查哪些条目是NA...\n", index.isna())

输出

这将产生以下输出 –

Pandas Index...
Float64Index([5.0, 65.0, nan, 17.0, 75.0, nan], dtype='float64')

索引中元素的数量...
6

数据的dtype对象...
float64

检查哪些条目是NA...
[False False True False False True]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程