I get 'TypeError: data type not understood' when trying to execute a line of code that looks like this:
df['c'].replace(0, method='ffill', inplace=True)
The code above is basically to replace every zero value with its previous non-zero value in column c
. The data type of values in column c
is integer with only two NaNs. The error still occurs after replacing the NaNs with zeros, but it works fine when I add the following line before the above code:
df.dropna(inplace = True)
So what does actually happen here? How can I replace every zero value with its previous non-zero value in column c
without deleting any row with NaNs in my DataFrame?