I would like a simple method for mapping float ranges to strings and saving back to a dataframe. I understand you can not use range() with floats.
setup df
import pandas as pd
d = [1.1, 5.6, 7.9, 6.2]
df = pd.DataFrame(data=d)
Mapping dictionary or this could be an if else block if needs be, I prefer a dict as it is quicker to setup but happy to use if else should there be a simplar solution that way.
grade_dict = {
(0, 4.9) :'average 4th-grade student or lower',
(5.0, 5.9) :'average 5th or 6th-grade student',
(6.0, 6.9) :'average 7th or 8th-grade student',
(7.0, 7.9) :'average 9th or 10th-grade student',
(8.0, 8.9) :'average 11th or 12th-grade student',
(9.0, 9.9) :'average 13th to 15th-grade (college) student'}
Then I want to do something like this
df['dale_chall_readability_score'] = df['dale_chall_readability_score'].map(grade_dict)
I am thinking there is something I am missing as I am finding it tricky put together a working solution for this.