일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 파이썬
- string
- matplotlib
- math
- list
- google apps script
- Python
- GIT
- Redshift
- Excel
- PANDAS
- django
- Java
- array
- SQL
- c#
- numpy
- Kotlin
- Google Spreadsheet
- dataframe
- PostgreSQL
- Mac
- gas
- hive
- PySpark
- Tkinter
- Github
- Google Excel
- Apache
- Today
- Total
목록Python/Python Pandas (77)
달나라 노트
DataFrame의 행이 많아서 일부 행만 확인하고 싶을 때 또는 어떠한 이유로 처음 또는 끝의 일부 행만 추출해야할 때 사용할 수 있는 method가 있습니다. Syntax DataFrame.head() # 상위 5개 행 반환 DataFrame.tail() # 하위 5개 행 반환 DataFrame.head(n) # 상위 n개 행 반환 DataFrame.tail(n) # 하위 n개 행 반환 사용법은 위와 같습니다. DataFrame에 적용할 수 있으며, head는 기본적으로 DataFrame의 가장 위쪽 5개 행을 return해주고 tail은 기본적으로 DataFrame의 가장 아래쪽 5개 행을 return해줍니다. head, tail의 parameter로 어떤 숫자를 넣게 되면 해당 숫자만큼의 행만큼 ..

dataframe_image library를 이용하면 Pandas의 DataFrame을 image로 저장할 수 있습니다. pip install dataframe-image 먼저 위처럼 dataframe-image library를 설치합시다. 설치시에는 underscore(_)가 아니라 dash(-)를 써야합니다. import pandas as pd import dataframe_image as dfi dict_item = { 'item_id': [1, 1, 3, 4], 'item_name': ['a', 'a', 'c', 'd'], 'price': [1000, 2000, 3000, 4000], 'flag': ['n', 'y', 'y', 'n'] } df_item = pd.DataFrame(dict_item..
pandas의 to_dict는 DataFrame에 적용하여 DataFrame을 dictionary로 변경해줍니다. import pandas as pd dict_1 = { 'col1': [1, 2, 3, 4, 5], 'col2': [6, 7, 8, 9, 10], 'col3': [11, 12, 13, 14, 15] } df_1 = pd.DataFrame(dict_1) print(df_1) dict_1 = df_1.to_dict() print(dict_1) -- Result col1 col2 col3 0 1 6 11 1 2 7 12 2 3 8 13 3 4 9 14 4 5 10 15 {'col1': {0: 1, 1: 2, 2: 3, 3: 4, 4: 5}, 'col2': {0: 6, 1: 7, 2: 8, 3: 9..
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 ..