반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- Mac
- PySpark
- numpy
- Apache
- PostgreSQL
- Excel
- gas
- django
- array
- Redshift
- list
- string
- Google Spreadsheet
- Java
- google apps script
- dataframe
- math
- Google Excel
- GIT
- matplotlib
- Github
- Tkinter
- hive
- PANDAS
- SQL
- 파이썬
- c#
- Python
- Kotlin
Archives
- Today
- Total
달나라 노트
Python Pandas : DataFrame.min, DataFrame.max (컬럼간의 최소값, 최대값) 본문
Python/Python Pandas
Python Pandas : DataFrame.min, DataFrame.max (컬럼간의 최소값, 최대값)
CosmosProject 2022. 5. 3. 01:28728x90
반응형
Syntax
DataFrame.min(axis=1)
DataFrame.max(axis=1)
min method는 DataFrame에 적용하여 컬럼간에 가장 작은 값을 return합니다.
max method는 DataFrame에 적용하여 컬럼간에 가장 작은 값을 return합니다.
import pandas as pd
dict_item = {
'col1': [1, 2, 3, 4, 5],
'col2': [5, 4, 3, 2, 1],
}
df_item = pd.DataFrame(dict_item)
df_item.loc[:, 'min_col'] = df_item.loc[:, ['col1', 'col2']].min(axis=1)
df_item.loc[:, 'max_col'] = df_item.loc[:, ['col1', 'col2']].max(axis=1)
print(df_item)
-- Result
col1 col2 min_col max_col
0 1 5 1 5
1 2 4 2 4
2 3 3 3 3
3 4 2 2 4
4 5 1 1 5
실제 사용 예시입니다.
- df_item.loc[:, 'min_col'] = df_item.loc[:, ['col1', 'col2']].min(axis=1)
df_item의 col1, col2 컬럼 데이터 중 더 작은 값을 min_col에 할당하고있습니다.
- df_item.loc[:, 'max_col'] = df_item.loc[:, ['col1', 'col2']].max(axis=1)
df_item의 col1, col2 컬럼 데이터 중 더 큰 값을 max_col에 할당하고있습니다.
728x90
반응형
'Python > Python Pandas' 카테고리의 다른 글
Comments