-1

so I am importing (row[3]) from excel which prints the prices set on the spreadsheet but I'm trying to calculate all the prices and find their average. I have them totalled up but I can't print(row[3])/100*15) because the row is not defined as an integer because it has a '£' sign. Anyone have an idea how I can get around this?

Thanks

ChaosPredictor
  • 3,777
  • 1
  • 36
  • 46
Joe
  • 1
  • 1
  • 3
    Possible duplicate of [How do I convert a currency string to a floating point number in Python?](https://stackoverflow.com/questions/8421922/how-do-i-convert-a-currency-string-to-a-floating-point-number-in-python) – Sayse Oct 21 '18 at 19:49
  • Yeah I saw this but he's assigning the value to a variable whereas I'm trying to convert it directly from the row – Joe Oct 21 '18 at 19:59
  • How is `row[3]` different to the "variable" they're using? – Sayse Oct 21 '18 at 20:01

1 Answers1

0

You can replace the symbol with an empty space, and then convert the string to a float. For example float('34$56'.replace('$','')) will return 3456.0 no matter where the $ is.

Emma G.
  • 1
  • 1