df['Current Ver'] = df['Current Ver'].astype(str).apply(lambda x : x.replace('.', ',',1).replace('.', '').replace(',', '.',1)).astype(float)
Slowly learning lambda command, my understanding of this line of code is:
- Change dataframe type to
str
- Apply
lambda
with one perimeterx
- Replace all the string format
.
to,
, (I don't understand what does1
stands for, have done research prior asking, didn't find clue) - Replace all the string format
.
tonull
value - Replace all the string format
,
to.
, (again still have no clue what does1
stands for in this case) - Change dataframe type to
float
Please help me better understanding this line of code, thank you
CodePudding user response:
This replaces the first .
in the string with a ,
, removes the remaining periods, changes the first ,
back to a .
, then converts the result to a float for the 'Current Ver'
column in the dataframe.