0

Titles quite self explanatory, im Struggling to perform mathematical operations on a value in python. So i basically get data from yahoo finance and am trying to perform operations on it

A = df['Total Assets']  #Isolates Assets
print(A)                #Prints Assets
B = A[3]                #Finds third element of that
print(B)                #Prints it
Output = int(float(B))
Output*3

Heres the error code

So simply in this example i have '1,376,402' and i want to multiply it by 3.

Any help is incredibly appreciated.

  • 2
    Does this answer your question? [How to convert a string to a number if it has commas in it as thousands separators?](https://stackoverflow.com/questions/1779288/how-to-convert-a-string-to-a-number-if-it-has-commas-in-it-as-thousands-separato) – fakedad Jul 01 '20 at 01:55

1 Answers1

1

The problem is that there are commas in the input you are attempting to convert to an integer.

Here is what you should do instead: int(B.replace(",", ""))

This replaces the commas with an empty string, which removes the commas from the string, and then it converts the number into an integer. Also, there is no need to convert a value to a float before converting it to an integer, so I omitted that part from my answer.

I hope this helps!

Sagar Patil
  • 507
  • 2
  • 7
  • 18