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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…