import pandas as pd
df = pd.DataFrame([['NewJersy',0,'2020-08-29'],
['NewJersy',12,'2020-08-30'],
['NewJersy',12,'2020-08-31'],
['NewJersy',None,'2020-09-01'],
['NewJersy',None,'2020-09-02'],
['NewJersy',None,'2020-09-03'],
['NewJersy',5,'2020-09-04'],
['NewJersy',5,'2020-09-05'],
['NewJersy',None,'2020-09-06'],
['NewYork',None,'2020-08-29'],
['NewYork',None,'2020-08-30'],
['NewYork',8,'2020-08-31'],
['NewYork',7,'2020-09-01'],
['NewYork',None,'2020-09-02'],
['NewYork',None,'2020-09-03']],
columns=['FName', 'FVal', 'GDate'])
print(df)
I want to fill NULL value with previous record values. For example Column FValue has values NULL for 20-09-01 to 20-09-03. The NULL value should be replaced with value 12 taken from previous valid value i.e.,from 20-08-31.
Also if the value for date 2020-08-29 is null then it should be replaced with zero as it is the first date and it doesn't have previous record.
I tried below code but not working
df['F'] = df['F'].fillna(method='ffill')
Check for Expected Values here: Fill Null Values image
Thanks