EDITED:
I have (not a very simple) a dataframe:
df = pd.DataFrame([1, 2, np.nan, np.nan, np.nan, np.nan, 3, 4
, np.nan, np.nan, np.nan, 5], columns=['att1'])
att1
0 1.0000
1 2.0000
2 nan
3 nan
4 nan
5 nan
6 3.0000
7 4.0000
8 nan
9 nan
10 nan
11 5.0000
I want fill NAN
values with the previous not NAN
value except the last NAN
value. I want the last NAN
value to be NAN
after filling. How can I do that?
I want this result:
att1
0 1.0000
1 2.0000
2 2.0000
3 2.0000
4 2.0000
5 nan
6 3.0000
7 4.0000
8 4.0000
9 4.0000
10 nan
11 5.0000
I tried this:
df = df.fillna(value='missing', method='bfill', limit=1)
df = df.fillna(method='ffill')
But the first row gives this error:
ValueError: cannot specify both a fill method and value
Why there is this limitation in pandas 0.17.1 / Python 3.5? Thank you!