일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- SQL
- gas
- hive
- Excel
- Github
- matplotlib
- c#
- Redshift
- Apache
- Java
- string
- numpy
- list
- Mac
- Tkinter
- Python
- Google Excel
- array
- Kotlin
- math
- django
- PySpark
- google apps script
- 파이썬
- GIT
- PANDAS
- PostgreSQL
- dataframe
- Google Spreadsheet
- Today
- Total
목록Python/Python Pandas (76)
달나라 노트
Pandas를 통해서 데이터를 다루다 보면 간혹 multi index가 생기는 경우가 있습니다. 특히 pivot_table() method를 사용한 후에 자주 발생하는데 이런 경우는 사실 다루기가 마냥 좋은 상태는 아닙니다. import pandas as pd multi_cols = pd.MultiIndex.from_tuples( [ ('number', 'date'), ('number', 'item'), ('string', 'item_name') ] ) df_test = pd.DataFrame( [ (20230101, 1, 'a'), (20230101, 2, 'b'), (20230101, 3, 'c'), (20230102, 1, 'a'), (20230102, 3, 'c'), (20230103, 2, 'b..
Pandas의 info() method는 DataFrame이나 Series의 정보를 보여줍니다. 바로 예시를 봅시다. import pandas as pd df_test = pd.DataFrame( { 'date': [ 20230101, 20230101, 20230101, 20230101, 20230102, 20230102, 20230102, 20230103, 20230103, ], 'item': [ 1, 1, 2, 2, 1, 1, 1, 5, 7, ], 'item_name': [ 'a', 'a', 'b', 'b', 'a', 'a', 'a', 'e', 'g', ] } ) print(df_test) print(df_test.info()) -- Result date item item_name 0 20230101..
nunique() method는 DataFrame이나 Series에 있는 값들 중 중복값을 제거한 unique한 값의 개수를 return합니다. 바로 예시를 봅시다. import pandas as pd df_test = pd.DataFrame( { 'col1': [1, 1, 3, 3, 4, 4, 4], 'col2': [8, 8, 8, 8, 8, 9, 9], } ) print(df_test) nunique_result = df_test.nunique() print(nunique_result) print(type(nunique_result)) -- Result col1 col2 0 1 8 1 1 8 2 3 8 3 3 8 4 4 8 5 4 9 6 4 9 col1 3 col2 2 dtype: int64 df_t..
pandas의 rank() method는 특정 column을 기준으로 ranking을 매겨줍니다. Syntax rank(ascending={True, False}, method={'min', 'max', 'dense', 'first', 'average'}, pct={True, False}, na_option={'keep', 'top', 'bottom}, numeric_only={True, False}) - ascending (default = True) True -> ranking을 매길 때 오름차순으로 정렬하여 rank를 매김. 따라서 원본 데이터가 더 작은 값일수록 더 1위에 가까운 rank를 얻게 됨. False -> ranking을 매길 때 내림차순으로 정렬하여 rank를 매김. 따라서 원본 데이..