-3

I have a code for sorting the prices:

new_prices = list(map(lambda price: int(price.replace('.', '').replace(',00', '').strip('Rp. ')), productprices))
final_list = list(zip(productlinks, productnames, new_prices, productimages))
sorted_list = pd.DataFrame(final_list).sort_values(by = 2).values

my price data is like: ['123.000,00', '122.000,00', '150.000,00'] -> it will be sorting according to the lowest price. But the problem is when the prices is like '121.000,69' it will get error, due to poor code, replace '00' to ''. so if the number behind comma is not '00' it will get error.

Awan
  • 17
  • 6
  • [How can I convert a string with dot and comma into a float in Python](https://stackoverflow.com/q/6633523/1324033) – Sayse May 30 '22 at 13:16
  • What about something like `int('121.000,69'.replace('.', '').split(',')[0])`? – Matthias May 30 '22 at 13:25
  • @Matthias error with: new_prices = list(map(lambda price: int(price.replace('.', '').replace(',').[0].strip('$ ')), prices)) ^ SyntaxError: invalid syntax – Awan May 30 '22 at 13:31
  • @Awan You missed the `split`. – Matthias May 30 '22 at 13:38

0 Answers0