Relative Content

Tag Archive for pythonpandas

How to swap values between two columns based on conditions in Python

I am trying to switch values between the Range and Unit columns in the dataframe below based on the condition that if Unit contains -, then replace Unit with Range and Range with Unit. To do that, I am creating a unit_backup column so that I don’t lose the original Unit value.