일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- PostgreSQL
- Python
- Google Spreadsheet
- SQL
- google apps script
- list
- GIT
- numpy
- hive
- 파이썬
- PANDAS
- Google Excel
- Github
- gas
- array
- string
- Kotlin
- dataframe
- Apache
- Redshift
- Mac
- Java
- Tkinter
- PySpark
- Excel
- c#
- django
- matplotlib
- math
- Today
- Total
목록Python/Python Pandas (77)
달나라 노트
Pandas로 DataFrame을 다루다보면 DataFrame data를 database에 load해야 할 경우가 있습니다. 따라서 아래처럼 create table 구문을 실행시켜 database table을 생성하고 해당 tabe에 insert하는 방법을 사용한다고 가정해봅시다. create table test_table ( col1 varchar, col2 bigint, col3 double ) 위 예시는 column이 3개밖에 없어서 다행이지만 만약 column이 30개인 DataFrame을 insert하려고 한다면 위 create table syntax에 column 30개에 대한 datatype을 일일이 적어줘야 할것입니다. 이는 너무 번거로운 작업이 아닐 수 없죠. pandas에는 위처럼 특정..
pandas의 values는 DataFrame에 적용하여 해당 DataFrame을 numpy arrary의 형태로 변환해줍니다. import pandas as pd dict_test = { 'col1': [1, 2, 3, 4, 5], 'col2': ['a', 'b', 'c', 'd', 'e'], 'col3': [6, 7, 8, 9, 10] } df_test = pd.DataFrame(dict_test) print(df_test) print(df_test.values) -- Result col1 col2 col3 0 1 a 6 1 2 b 7 2 3 c 8 3 4 d 9 4 5 e 10 [[1 'a' 6] [2 'b' 7] [3 'c' 8] [4 'd' 9] [5 'e' 10]] 위 예시를 보면 Test용 ..
pandas의 shape은 DataFrame에 적용해서 해당 DataFramedml 행/열(row/column) 개수를 tuple의 형태로 반환해줍니다. shape의 syntax는 다음과 같습니다. DataFrame.shape import pandas as pd dict_test = { 'col1': [1, 2, 3, 4, 5], 'col2': ['a', 'b', 'c', 'd', 'e'], 'col3': [6, 7, 8, 9, 10] } df_test = pd.DataFrame(dict_test) print(df_test) print(df_test.shape) -- Result col1 col2 col3 0 1 a 6 1 2 b 7 2 3 c 8 3 4 d 9 4 5 e 10 (5, 3) 위 예시를 보..
Python Pandas에서 제공하는 melt method는 가로 데이터를 세로 데이터로 변경해주는 기능을 가지고있습니다. (가로 데이터를 세로 데이터로 변경하는것을 보통 unpivot이라고 합니다.) Pandas pivot_table method와 반대의 개념이죠. Pandas pivot_table 참고 https://cosmosproject.tistory.com/29 Python Pandas : pandas.pivot_table pandas.pivot_table pivot_table은 세로 데이터를 가로 데이터로 변경해주는 역할을 합니다. 먼저 테스트용 DataFrame을 생성합시다. import pandas as pd dict_1 = { 'dt': [20201201, 20201201, 2020120..