samedi 24 novembre 2018

Function to band values in a dataframe [duplicate]

This question already has an answer here:

Trying to write a function to band values in a dataframe. Below is what I've got but it throws the error: 'str' object has no attribute 'isbetween'. Not sure if my if-statement is correct either. Any thoughts appreciated.

def get_valueband(value):
valueband = None
if value == '':
    valueband = ''
elif value.isbetween(0,25):
    valueband = '0to25'
elif value.isbetween(25,50):
    valueband = '25to50'
elif value.isbetween(50,75):
    valueband = '50to75'
else:
    valueband = '75to100'
return valueband

turnover_question['answer_value_band'] = turnover_question.answer_value.apply(get_valueband)

Aucun commentaire:

Enregistrer un commentaire