Python Pandas TimedeltaIndex.fillna
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas TimedeltaIndex.fillna()函数将给定的TimedeltaIndex对象中的所有缺失值都填充为指定的值。
语法: TimedeltaIndex.fillna(value=None, downcast=None)
参数 :
value : 用来填补漏洞的标量值(例如0)。这个值不能是一个列表式的。
downcast : item->dtype的一个dict,如果可能的话,要进行下转换,或者字符串’infer’,它将尝试下转换到一个适当的等价类型(例如,如果可能的话,float64到int64)。
返回 : 填充 : %(klass)s
例子#1:使用TimedeltaIndex.fillna()函数来填补所有缺失的值,即给定的TimedeltaIndex对象。
# importing pandas as pd
import pandas as pd
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =[None, '1 days 06:05:01.000030', None,
'1 days 02:00:00', '21 days 06:15:01.000030'])
# Print the TimedeltaIndex object
print(tidx)
输出 :
现在我们将使用TimedeltaIndex.fillna()函数来填补tidx对象中所有的缺失值。
# fill the missing values
tidx.fillna('10 days')
输出 :
正如我们在输出中看到的,TimedeltaIndex.fillna()函数已经用tidx对象中的指定值填充了所有缺失的值。
示例#2:使用TimedeltaIndex.fillna()函数来填补所有缺失的值,即给定的TimedeltaIndex对象。
# importing pandas as pd
import pandas as pd
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =['06:05:01.000030', None, '22 day 2 min 3us 10ns',
'+23:59:59.999999', None, '+12:19:59.999999'])
# Print the TimedeltaIndex object
print(tidx)
输出 :
现在我们将使用TimedeltaIndex.fillna()函数来填补tidx对象中所有的缺失值。
# fill the missing values
tidx.fillna('2 days 10:50')
输出 :
正如我们在输出中看到的,TimedeltaIndex.fillna()函数已经用tidx对象中的指定值填充了所有缺失的值。