Reputation: 1127
As in the question above, is there any other way to do it? Because I care about not using values np.nan.
Input dataframe:
col_1
a
x
b
x
x
c
x
Output:
col_1
a
a
b
b
b
c
c
Upvotes: 2
Views: 65
Reputation: 3379
Well, a quick way could be:
df["col_1"].str.replace("^x$", lambda x: np.nan).ffill()
So, instead of rebuilding a ffill
logic, just try to leverage the existing one.
Upvotes: 1