Python Pandas - 用索引对象中的指定值填充 NaN 值
要使用Index对象中的指定值填充NaN值,请使用Pandas中的方法。首先,导入所需的库-index.fillna()
import pandas as pd import numpy as np
使用一些NaN值创建Pandas索引-
index = pd.Index([50, 10, 70, np.nan, 90, 50, np.nan, np.nan, 30])
显示熊猫指数-
print("Pandas Index...\n",index)用一些特定的值填充NaN-
print("\nIndex object after filling NaN value...\n",index.fillna('Amit'))示例
以下是代码-
import pandas as pd
import numpy as np
#还使用一些NaN值创建Pandas索引
index = pd.Index([50, 10, 70, np.nan, 90, 50, np.nan, np.nan, 30])
#显示Pandas索引
print("Pandas Index...\n",index)
#返回索引中的元素数
print("\nNumber of elements in the index...\n",index.size)
#返回数据的dtype
print("\nThe dtype object...\n",index.dtype)
#用一些特定的值填充NaN
print("\nIndex object after filling NaN value...\n",index.fillna('Amit'))输出结果这将产生以下输出-
Pandas Index... Float64Index([50.0, 10.0, 70.0, nan, 90.0, 50.0, nan, nan, 30.0], dtype='float64') Number of elements in the index... 9 The dtype object... float64 Index object after filling NaN value... Index([50.0, 10.0, 70.0, 'Amit', 90.0, 50.0, 'Amit', 'Amit', 30.0], dtype='object')
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便