0

I want to mutiply the column prix in pandas df * 1000 but it returns an expected value and I didn't know why it works like that. for exemple i want to return 57 to 257000 but it turns it like this 5757575757575757575757575757575757575757575757

I used this code

 c['prix'] = c['prix'].apply(lambda x: x * 1000 if len(str(x)) == 2 else x) 

How to fix it please

kim seol
  • 15
  • 2

1 Answers1

0

Ensure to have integers and use vectorial code:

# convert strings to numeric
c['prix'] = pd.to_numeric(c['prix'], errors='coerce')

# multiply numbers with 2 digits by 1000
c.loc[c['prix'].between(10, 99), 'prix'] *= 1000
mozway
  • 194,879
  • 13
  • 39
  • 75