0

I'm trying to replace values in my dataframe lower than 5.5 with 'insufficient' and higher than 5.5 with 'sufficient' using the following code:

import numpy as np

df['test'] = np.where(df['grade'] > 5.5, 'sufficient', 'insufficient')

This gives me the following error: TypeError: '>' not supported between instances of 'str' and 'float'

How do I replace my float dataframe values with strings?

user3478148
  • 433
  • 1
  • 8
  • 26

1 Answers1

0

Check df['grade'] include string type values. Or, try df['grade'].astype(float) > 5.5

Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58
Gilseung Ahn
  • 2,598
  • 1
  • 4
  • 11