python - Pandas: Fill missing values using last available -
i have dataframe follows:
b zdate 01-jan-17 100 200 02-jan-17 111 203 03-jan-17 nan 202 04-jan-17 109 205 05-jan-17 101 211 06-jan-17 105 nan 07-jan-17 104 nan
what best way, fill missing values, using last available ones?
following intended result:
b zdate 01-jan-17 100 200 02-jan-17 111 203 03-jan-17 111 202 04-jan-17 109 205 05-jan-17 101 211 06-jan-17 105 211 07-jan-17 104 211
use ffill
function, same fillna
method ffill
:
df = df.ffill() print (df) b zdate 01-jan-17 100.0 200.0 02-jan-17 111.0 203.0 03-jan-17 111.0 202.0 04-jan-17 109.0 205.0 05-jan-17 101.0 211.0 06-jan-17 105.0 211.0 07-jan-17 104.0 211.0
Comments
Post a Comment