In R, there is a rather useful replace function.
Essentially, it does conditional re-assignment in a given column of a data frame.
It can be used as so:
replace(df$column, df$column==1,'Type 1');
What is a good way to achieve the same in pandas?
Should I use a lambda with apply? (If so, how do I get a reference to the given column, as opposed to a whole row).
Should I use np.where on data_frame.values?
It seems like I am missing a very obvious thing here.
Any suggestions are appreciated.
pandashas areplacemethod too:or you could use
numpy-style advanced indexing: