用 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
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下