Pandas 係列是帶有軸標簽的一維ndarray。標簽不必是唯一的,但必須是可哈希的類型。該對象同時支持基於整數和基於標簽的索引,並提供了許多方法來執行涉及索引的操作。
Pandas Series.ffill()
函數是正向填充的同義詞。此函數用於使用正向填充方法填充給定係列對象中的缺失值。
用法: Series.ffill(axis=None, inplace=False, limit=None, downcast=None)
參數:
axis:{0或“索引”}
inplace:如果為True,則填寫。
limit:如果指定了method,則這是要向前/向後填充的連續NaN值的最大數量
downcast:dict,默認為無
返回:填充:係列
範例1:采用Series.ffill()
函數來填充給定係列對象中的缺失值。
# 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)
輸出:
現在我們將使用Series.ffill()
函數來填充給定係列對象中的缺失值。
# fill the missing values
result = sr.ffill()
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.ffill()
函數已成功填寫給定係列對象中的缺失值。
範例2:采用Series.ffill()
函數來填充給定係列對象中的缺失值。
# 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.ffill()
函數來填充給定係列對象中的缺失值。
# fill the missing values
result = sr.ffill()
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.ffill()
函數已成功填寫給定係列對象中的缺失值。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Timestamp.tz用法及代碼示例
- Python Pandas Series.str.contains()用法及代碼示例
- Python Pandas dataframe.std()用法及代碼示例
- Python Pandas Timestamp.dst用法及代碼示例
- Python Pandas dataframe.sem()用法及代碼示例
- Python Pandas DataFrame.ix[ ]用法及代碼示例
- Python Pandas.Categorical()用法及代碼示例
- Python Pandas.apply()用法及代碼示例
- Python Pandas TimedeltaIndex.contains用法及代碼示例
- Python Pandas Timestamp.now用法及代碼示例
- Python Pandas Series.str.pad()用法及代碼示例
- Python Pandas Series.take()用法及代碼示例
- Python Pandas dataframe.all()用法及代碼示例
- Python Pandas series.str.get()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Series.ffill()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。