일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- PANDAS
- Google Spreadsheet
- SQL
- math
- numpy
- Github
- Google Excel
- GIT
- google apps script
- dataframe
- PySpark
- Tkinter
- Mac
- gas
- PostgreSQL
- django
- Apache
- Kotlin
- hive
- c#
- Java
- Python
- string
- 파이썬
- matplotlib
- Excel
- Redshift
- array
- list
- Today
- Total
목록Python (384)
달나라 노트
pandas의 transpose는 DataFrame의 행/열을 서로 변경한 새로운 DataFrame을 생성해줍니다. import pandas as pd dict_1 = { 'col1': [1, 2, 3, 4, 5], 'col2': [6, 7, 8, 9, 10], 'col3': [11, 12, 13, 14, 15], 'col4': [16, 17, 18, 19, 20] } df_1 = pd.DataFrame(dict_1) print(df_1) df_2 = df_1.transpose() print(df_2) -- Result col1 col2 col3 col4 0 1 6 11 16 1 2 7 12 17 2 3 8 13 18 3 4 9 14 19 4 5 10 15 20 0 1 2 3 4 col1 1 2 3 4 ..
DataFrame은 기본적으로 index가 0부터 1씩 증가하는 정수로 생성됩니다. 다만 set_index를 이용하면 DataFrame의 index를 원하는대로 변경할 수 있습니다. Syntax set_index(keys=[k1, k2, ...], inplace=True/False, drop=True/False) 사용법은 위와 같습니다. keys=[k1, k2, ...] index로 설정할 list 형태의 데이터입니다. index는 보통 1줄이지만 2줄 3줄 또는 그 이상이 될 수도 있습니다. (다중 index가 가능하다는 의미입니다.) k1은 index 한 줄 이라고 보시면 됩니다. 예를들어 총 10행의 데이터를 가진 DataFrame의 index를 변경하려면 k1의 자리에 [1, 2, 3, 4, 5,..
이 글에선 Pandas의 DataFrame에 groupby와 rolling method를 동시에 사용하는 예시를 보겠습니다. 이 글 이전에 아래 2개의 글을 먼저 읽고 오면 이해하는데 도움이 됩니다. https://cosmosproject.tistory.com/156 Python Pandas : rolling (DataFrame window function) Pandas에서 사용할 수 있는 window function 기능을 알아봅시다. import pandas as pd dict_test = { 'col1': [1, 1, 2, 2, 3, 3, 3, 4], 'col2': [1000, 1100, 2100, 2050, 3000, 3100, 3200, 4200], 'col3': ['a.. cosmosproje..
min, max method를 이용하면 컬럼간의 값 비교가 가능해집니다. import pandas as pd import numpy as np dict_test = { 'col1': [1, 2, np.nan, 4, 5], 'col2': [6, 2, 7, 3, 9], 'col3': [10, 6, 22, np.nan, 21] } df_test = pd.DataFrame(dict_test) print(df_test) -- Result col1 col2 col3 0 1.0 6 10.0 1 2.0 2 6.0 2 NaN 7 22.0 3 4.0 3 NaN 4 5.0 9 21.0 먼저 test용 DataFrame을 위처럼 생성합시다. import pandas as pd import numpy as np dict_tes..