0

I converted a column from objects to floats and in order for that I had to add zeros for the blank space is there any way to remove the zeros without changing the number. I don't want to round the numbers as I need them to stay the same.

Image 1 This is how I want it to look.

image 2 But this is how it looks right now

luis
  • 1
  • 3

1 Answers1

0

You can split each string by an empty string, join them by 0, and convert to float:

df['FG%'] = df['FG%'].str.split('').str.join('0').astype(float)
  • I did this using lambda but now I have extra zeros – luis May 04 '22 at 16:28
  • Can you provide an example? –  May 04 '22 at 16:28
  • `stats_test['3P%'] = stats_test['3P%'].apply(lambda x: x.replace("", "0"))` I used this because I couldn't just apply the `.astype(float)` to the column – luis May 04 '22 at 16:32
  • ValueError: could not convert string to float: ' ' This was the error I was getting when applying `.astype(float)` without apply lambda – luis May 04 '22 at 16:36