i want apply lambda to do multiplication which is condition type data float value like this
0.412
0.0036
0.0467
0.000678
0.00000342
expected output
0.41
0.36
0.47
0.68
0.34
CodePudding user response:
You can use replace
with astype
and round
.
Try this :
df["col"] = df["col"].replace("\.0*", ".", regex=True).astype(float).round(2)
# Output :
print(df)
col
0 0.41
1 0.36
2 0.47
3 0.68
4 0.34
CodePudding user response:
Try this:
import re
lambda_func = lambda x: re.sub(r'(\.0*)', r'.', str(x))