| 1번째 줄: |
1번째 줄: |
| | == 개요 == | | == 개요 == |
| | + | 파생변수에 대해 다루는 문서. |
| | + | |
| | dataframe의 평균, 합을 구한다든가 특정 연산을 수행해야 할 때가 있다. for문으로 일일이 할 수도 있지만, 효율이 그닥 좋진 않다. | | dataframe의 평균, 합을 구한다든가 특정 연산을 수행해야 할 때가 있다. for문으로 일일이 할 수도 있지만, 효율이 그닥 좋진 않다. |
| | | | |
| 110번째 줄: |
112번째 줄: |
| | |<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> |
| 118번째 줄: |
119번째 줄: |
| | |<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> |
| | |} | | |} |