데이터 분석/[Python] Troubleshooting
[Python] np.where 조건 여러개 TypeError
INCHELIN
2021. 8. 17. 09:15
728x90
np.where(조건, True일 경우 값, False일 경우 값)
조건이 여러개일 경우 &또는 |로 표현할 수 있는데 TypeError를 만날 수 있다..
df['면적대'] = np.where(df['면적'] > 500 & df['면적'] <=1000, "A", "B")
TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
조건문에 괄호문( )을 적절하게 열고 닫아줘야 한다!
df['면적대'] = np.where((df['면적'] > 500) & (df['면적'] <=1000), "A", "B")
728x90