Home > Mobile >  Python pandas looping trough columns
Python pandas looping trough columns

Time:10-24

I am trying to figure out how to loop trough 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 for loop like so:

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

If anyone could help me figuring this out...

CodePudding user response:

I would do:

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

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