일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Mac
- c#
- Apache
- string
- PANDAS
- math
- gas
- GIT
- numpy
- list
- SQL
- google apps script
- Java
- Redshift
- array
- matplotlib
- dataframe
- 파이썬
- Google Excel
- django
- hive
- Kotlin
- Google Spreadsheet
- Python
- Excel
- Github
- PySpark
- Tkinter
- Today
- Total
목록Python/Python Pandas (77)
달나라 노트
Pandas의 shift method는 DataFrame이나 Series에 적용해서 행의 위치를 일정 칸수씩 이동시킵니다. 바로 예시를 통해 알아봅시다. import pandas as pd dict_test = { 'col1': [ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4 ], 'col2': [ 'a', 'a', 'a', 'b', 'b', 'b', 'a', 'a', 'b', 'b', 'a', 'a', 'b', 'a', 'b', 'b' ], 'col3': [ 1000, 1100, 1200, 1300, 1050, 1100, 2100, 2050, 2000, 2200, 3000, 3100, 3200, 4200, 4100, 4150 ], 'col4': [ 1, 2, 3,..
Python Pandas에는 DataFrame이나 Series를 json 형태로 변환해주는 to_json이라는 method가 있습니다. 예시를 보시죠. import pandas as pd dict_test = { 'col1': [1, 2, 3, 4, 5], 'col2': ['a', 'b', 'c', 'd', 'e'], 'col3': ['Apple', 'Banana', 'Watermelon', 'Grape', 'Melon'] } df_test = pd.DataFrame(dict_test) print(df_test) json_test = df_test.to_json() print(json_test) -- Result col1 col2 col3 0 1 a Apple 1 2 b Banana 2 3 c Water..
Python pandas에는 duplicated라는 method가 있습니다. duplicated method는 DataFrame에 있는 행들 중 중복된 값을 가진 행이 뭔지 True, False의 형태로 알려줍니다. Syntax DataFrame.duplicated(subset=list/none, keep='first'/'last'/False) subset subset에는 중복값 테스트를 할 기준 column을 적습니다. 만약 subset을 적지 않으면 모든 컬럼의 데이터를 기준으로 중복값을 가진 row를 체크합니다. keep='first' --> 중복된 row 중에서 가장 위에 있는 row를 제외하고 나머지 row에 중복 flag(True)를 달아줍니다. keep='last' --> 중복된 row 중에..
DataFrame을 다루다보면 DataFrame에 있는 하나하나의 행을 참조하여 for loop를 돌리는 등의 경우가 발생합니다. 이럴때에는 여러 가지 방법이 있지만 그 중에서 pandas에서 제공하는 iterrows를 사용해봅시다. import pandas as pd dict_1 = { 'col1': [4, 1, 5, 3, 2], '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) print(df_1.iterrows()) -- Result col1 col2 col3 col4 0 4 6 11 16 1 1 7 12 17 2 5 8 1..