用 Python 编写一个程序来查找给定系列中 NaN 值的索引
输入-
假设你有一个系列,
0 1.0 1 2.0 2 3.0 3 NaN 4 4.0 5 NaN
输出-
并且,NaN索引的结果是,
index is 3 index is 5
解决方案
为了解决这个问题,我们将按照下面给出的步骤-
定义一个系列。
创建for循环并访问所有元素并将if条件设置为checkisnan()。最后打印索引位置。它定义如下,
for i,j in data.items():
if(np.isnan(j)):
print("index is",i)例子
让我们看看下面的实现,以便更好地理解。
import pandas as pd
import numpy as np
l = [1,2,3,np.nan,4,np.nan]
data = pd.Series(l)
print(data)
for i,j in data.items():
if(np.isnan(j)):
print("index is",i)输出结果0 1.0 1 2.0 2 3.0 3 NaN 4 4.0 5 NaN dtype: float64 index is 3 index is 5
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短