Python Pandas Series.ffill()

Python Pandas Series.ffill()

Pandas系列是一个带有轴标签的一维ndarray。标签不需要是唯一的,但必须是一个可散列的类型。该对象支持基于整数和标签的索引,并提供了大量的方法来执行涉及索引的操作。

Pandas Series.fill()函数是forward fill的同义词。这个函数用于在给定的系列对象中使用正向填充方法来填充缺失的值。

语法: Series.ffill(axis=None, inplace=False, limit=None, downcast=None)

参数:
axis: {0或’索引’}
inplace : 如果为真,就地填充。
limit : 如果指定了方法,这是要向前/向后填充的连续NaN值的最大数量。
downcast : dict,默认为无。

返回 :填充:系列

示例#1:使用Series.fill()函数来填补给定系列对象中的缺失值。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(['New York', 'Chicago', 'Toronto', None, 'Rio'])
  
# Create the Index
sr.index = ['City 1', 'City 2', 'City 3', 'City 4', 'City 5'] 
  
# set the index
sr.index = index_
  
# Print the series
print(sr)

输出 :
Python Pandas Series.ffill()

现在我们将使用Series.fill()函数来填补给定系列对象中的缺失值。

# fill the missing values
result = sr.ffill()
  
# Print the result
print(result)

输出 :
Python Pandas Series.ffill()
正如我们在输出中看到的,Series.fill()函数已经成功地填补了给定系列对象中的缺失值。

示例#2 :使用Series.fill()函数来填补给定系列对象中的缺失值。

# 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)

输出 :

Python Pandas Series.ffill()

现在我们将使用Series.fill()函数来填补给定系列对象中的缺失值。

# fill the missing values
result = sr.ffill()
  
# Print the result
print(result)

输出 :
Python Pandas Series.ffill()
正如我们在输出中看到的,Series.fill()函数已经成功地填补了给定系列对象中的缺失值。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程