I'm trying to write a function that goes through a pandas df series full of floats and converts them into one of four string categorical variables based on where they are in the series range. So all values in the ranges quartiles would be converted to either low, low_mid, high_mid, or high. I've done it a number of ways but keep getting various error messages. The latest attempt and its message is below. I'd appreciate it if some one could take a peek and toss out any ideas/fixes. Thanks!
def makeseriescategorical(x):
for i in x:
if i < 59863.0:
str(i)
i.replace(i, "low")
elif i > 59862.0 and i < 86855.0:
str(i)
i.replace(i, "low_mid")
elif i > 86854.0 and i < 125250.0:
str(i)
i.replace(i, "high_mid")
elif i > 125249.0 and i < 332801:
str(i)
i.replace(i, "high")
The error message I got on this last attempt was: AttributeError: 'numpy.float64' object has no attribute 'replace'
I've tried various other to ways to make it a string such as astype but I keep getting errors. I'm new to coding so I'm sure theres a strong chance I'm making a dumb mistake but I'd appreciate any help anyone can give me. Cheers.