데이터프레임에서 모든 원소에 로직 심어서 바꾸기¶
In [50]:
import numpy as np
array = np.random.randint(5, size=(5,3))
array
Out[50]:
In [52]:
np.where(array > 2, 5, 0)
Out[52]:
In [53]:
import pandas as pd
df = pd.DataFrame(array)
In [54]:
df
Out[54]:
In [58]:
m = {0:'hehe', 1: 'babo', 2: 'sexy', 3:'koko', 4:'fu'}
In [59]:
df.apply(lambda x: x.apply(lambda y : m[y]) , axis=1)
Out[59]: