Python type conversion error

Asked 1 years ago, Updated 1 years ago, 93 views

of Python, to list serise value from the string float I was about to change it to error

.

What's wrong?

The code intention is change_csv['Volume'] serise is 1.61M, 77.2K, and it's kilo and millon I want to make this 103,106 and calculate it, but I want to convert it into float by extracting only the string type.

3,to 6

python float error string

2022-09-22 15:51

1 Answers

I think you should check if element[:][:-1] really comes out in the form of "1.61M". Assuming so, turning the fixed code will produce a normal output.

str = "1.61558M"
num = float(str[:-1])
if str[-1:] == 'M' :
    num *= 1000000
print(int(num)) // 1615580


2022-09-22 15:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.