Pandas 系列是带有轴标签的一维ndarray。标签不必是唯一的,但必须是可哈希的类型。该对象同时支持基于整数和基于标签的索引,并提供了许多方法来执行涉及索引的操作。
 Pandas  Series.bfill()函数是向后填充方法的同义词。此函数用于填充给定系列对象中的缺失值。
用法: Series.bfill(axis=None, inplace=False, limit=None, downcast=None)
参数:
axis:轴= 1
inplace:对同一对象进行更改
limit:要填充的连续缺失值的最大数量
返回:系列
范例1:采用Series.bfill()函数来填充给定系列对象中的缺失值。
# importing pandas as pd 
import pandas as pd 
  
# Creating the Series 
sr = pd.Series(['New York', 'Chicago', 'Toronto', None, 'Rio']) 
  
# Create the Index 
index_ = ['City 1', 'City 2', 'City 3', 'City 4', 'City 5']  
  
# set the index 
sr.index = index_ 
  
# Print the series 
print(sr)输出:

现在我们将使用Series.bfill()函数来填充给定系列对象中的缺失值。
# fill the missing values using backward fill method 
result = sr.bfill() 
  
# Print the result 
print(result)输出:

正如我们在输出中看到的,Series.bfill()函数已使用向后填充方法成功填充了给定系列对象中的缺失值。
范例2:采用Series.bfill()函数来填充给定系列对象中的缺失值。
# importing pandas as pd 
import pandas as pd 
  
# Creating the Series 
sr = pd.Series([100, None, None, 18, 65, None, 32, 10, 5, 24, None]) 
  
# Create the Index 
index_ = pd.date_range('2010-10-09', periods = 11, freq ='M') 
  
# set the index 
sr.index = index_ 
  
# Print the series 
print(sr)输出:

现在我们将使用Series.bfill()函数来填充给定系列对象中的缺失值。
# fill the missing values using backward fill method 
result = sr.bfill() 
  
# Print the result 
print(result)输出:

正如我们在输出中看到的,Series.bfill()函数已使用向后填充方法成功填充了给定系列对象中的缺失值。请注意,最后一个值尚未填充,因为该元素之后的系列中没有有效值。
相关用法
- Python pandas.map()用法及代码示例
 - Python Pandas Series.str.len()用法及代码示例
 - Python Pandas.factorize()用法及代码示例
 - Python Pandas TimedeltaIndex.name用法及代码示例
 - Python Pandas dataframe.ne()用法及代码示例
 - Python Pandas Series.between()用法及代码示例
 - Python Pandas DataFrame.where()用法及代码示例
 - Python Pandas Series.add()用法及代码示例
 - Python Pandas.pivot_table()用法及代码示例
 - Python Pandas Series.mod()用法及代码示例
 - Python Pandas Dataframe.at[ ]用法及代码示例
 - Python Pandas Dataframe.iat[ ]用法及代码示例
 - Python Pandas.pivot()用法及代码示例
 - Python Pandas dataframe.mul()用法及代码示例
 - Python Pandas.melt()用法及代码示例
 
注:本文由纯净天空筛选整理自Shubham__Ranjan大神的英文原创作品 Python | Pandas Series.bfill()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
