| 110번째 줄: |
110번째 줄: |
| | |<code>df['over_5unit'] = np.where(df['1unit']>df['5unit'], True값, False값)</code> | | |<code>df['over_5unit'] = np.where(df['1unit']>df['5unit'], True값, False값)</code> |
| | <nowiki>#</nowiki> 1unit 행의 값이 5unit 행의 값보다 큰 때에만 True값을 넣는다. | | <nowiki>#</nowiki> 1unit 행의 값이 5unit 행의 값보다 큰 때에만 True값을 넣는다. |
| − |
| |
| | | | |
| | <code>df['열'] = np.where(조건, 참, np.where(조건, 참2, 거짓))</code> | | <code>df['열'] = np.where(조건, 참, np.where(조건, 참2, 거짓))</code> |
| 117번째 줄: |
116번째 줄: |
| | |특정 범주 안에 들어있는가 파악하기. | | |특정 범주 안에 들어있는가 파악하기. |
| | |<syntaxhighlight lang="python"> | | |<syntaxhighlight lang="python"> |
| − | 변수 = np.where( | + | 변수 = np.where( \ |
| − | (df['category'] == '값1') | (df['category'] == '값2') | ... , '참값', '거짓값' | + | (df['category'] == '값1') | (df['category'] == '값2') | ... , '참값', '거짓값') |
| − | )
| |
| | </syntaxhighlight>위 형태로는 너무 코드가 길어져서... 아래와 같이 축약하곤 한다.<syntaxhighlight lang="python"> | | </syntaxhighlight>위 형태로는 너무 코드가 길어져서... 아래와 같이 축약하곤 한다.<syntaxhighlight lang="python"> |
| − | 변수 = np.where( | + | 변수 = np.where( \ |
| − | df['category'].isin([값1, 값2, ...]) , '참값', '거짓값' | + | df['category'].isin([값1, 값2, ...]) , '참값', '거짓값') |
| − | )
| |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | |} | | |} |