Python: foward fill nans and zeros

Viewed 1561

Suppose I have a dataframe, df1, that has zeros and nans:

dates = pd.date_range('20170101',periods=20)
df1 = pd.DataFrame(np.random.randint(10,size=(20,3)),index=dates,columns=['foo','bar','see'])
df1.iloc[3:12,0] = np.nan
df1.iloc[6:17,1] = 0

What's the succinct way to forward fill both zeors and nans? I tried the below:

df1 = (df1.fillna(method='ffill', inplace=True)).replace(to_replace=0, method='ffill')

AttributeError: 'NoneType' object has no attribute 'replace'
2 Answers
Related