Reputation: 25
is there a way I can invert values in a dataframe using Pandas? I am using data representing customers feedback. It is captured as a value from 1 to 5, 5 being the best feedback and 1 the lowest. I would like to invert it so that 1 becomes the highest score, so basically all the 5s become 1s, 4 becomes 2 and 3 stays 3. Is there a way I can achieve that? Many thanks in advance.
Upvotes: 0
Views: 3037
Reputation: 41
The map function is used for substituting each value in a Series with another value. So, you should try:
df['col_name'] = df['col_name'].map({5:1, 4:2, ...})
Upvotes: 0