ref_url: http://deanla.com/dont_reinvent_pandas.html#Map-with-dict ref_name: DeanLa's Blog ---
A dict is a callable with $f(key) = value$, there for you can call .map
with it. In this
example I want to make int key codes into letter.
df.event_type.map(lambda x: x+3).head()
# A dict is also a calleble
df['event_type'] = df.event_type.map({
1:'A',
5:'B',
7:'C'
})
df.head()
event_type | |
---|---|
date_ | |
2018-10-09 17:01:30.662389 | B |
2018-10-09 17:01:30.687675 | B |
2018-10-09 17:03:23.952847 | A |
2018-10-09 17:05:42.327744 | C |
2018-10-09 17:06:29.708909 | C |