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
lambdawith one perimeterx - Replace all the string format
.to,, (I don’t understand what does1stands for, have done research prior asking, didn’t find clue) - Replace all the string format
.tonullvalue - Replace all the string format
,to., (again still have no clue what does1stands for in this case) - Change dataframe type to
float
Please help me better understanding this line of code, thank you
>Solution :
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.