I'm, trying to to add a new column to my df that will be mapped by ranges of other column in the same df. I'm using pandas.series.between()
function to define the new values but getting an error:
TypeError: unhashable type: 'Series'
This is what I have tried:
my_dict = {df['column'].between(0.0, 5.0) : 1,
df['column'].between(5.1, 7.0) : 2,
df['column'].between(7.1, 10.0) : 3,
df['column'].between(10.1, 13.0) : 4,
df['column'].between(13.1, 16.0) : 5,
df['column'].between(19.1, 22.0) : 6,
df['column'].between(22.1, 25.0) : 7,
df['column'].between(25.1, 28.0) : 8,
df['column'].between(28.1, 31.0) : 9,
df['column'].between(31.1, 34.0) : 10,
df['column'].between(34.1, 37.0) : 11,
df['column'].between(37.1, 40.0) : 12,
df['column'].between(40.1, df['column'].max()) : 13
}
df['new_column'] = df.map(my_dict)
If there's any other way to do that without s.bewtween() it will be also a good option.