Home > Software design >  Looping through columns using Python and Pandas
Looping through columns using Python and Pandas

Time:10-27

I am trying to figure out how to loop through columns to replace its values.

My dataset looks like this:

Enter image description here

In this example, I want to replace the decimal comma of the first two columns with decimal points.

When trying to use a for loop like

for col in opel_Df[['Altitude Variation', 'Vehicle Speed Instantaneous']]:
    opel_Df[col] = opel_Df[col].replace(',', '.')

nothing happens, but this is because I have to set inplace=True, but when I do so, I get none values:

Enter image description here

How can I do it?

CodePudding user response:

I would do:

col = ['Altitude Variation', 'Vehicle Speed Instantaneous']

opel_Df[col] = opel_Df[col].replace(',', '\.', regex=True)
  • Related