How can I replace all occurrences of 0 to 1 in my dataframe?

M

messy748

Guest
I am working with a dataframe that looks something like

duration count 0 23 2 12 0 43 2 12 0 43 4 65 1 22

I simply want to replace all of the 0's in the duration column with 1. I tried to do this by

df_sorted = df_sorted.replace(df_sorted['duration'] == 0, df_sorted['duration'] == 1)

However, I run this and the dataframe seems unaffected. I do not get an error message and nothing seems to change. I am working with a much bigger dataframe with a lot more rows/columns so maybe I'm missing that something else is changing? Regardless, the 0's still remain after I run the line of code.

Continue reading...
 
Top