일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- matplotlib
- django
- numpy
- list
- Apache
- Java
- PySpark
- SQL
- math
- array
- 파이썬
- Google Excel
- Kotlin
- google apps script
- Redshift
- Mac
- Tkinter
- Github
- hive
- gas
- dataframe
- PostgreSQL
- Excel
- c#
- Python
- GIT
- string
- Google Spreadsheet
- PANDAS
- Today
- Total
목록Python/Python Pandas (80)
달나라 노트
pandas의 sample method는 DataFrame에서 랜덤한 행을 추출해줍니다. Syntax DataFrame.sample(frac=float, replace=True/False, ignore_index=True/False) - frac 이 옵션은 0~1 사이의 실수를 받습니다. fraction의 약자로 원본 DataFrame의 존재하는 row의 개수 중 몇%를 추출할지를 결정합니다. 0.5는 원본 DataFrame에 존재하는 row의 개수가 10개라면 그의 50%인 5개만 추출합니다. 1은 원본 DataFrame에 존재하는 row의 개수가 10개라면 그의 100%인 10개를 추출합니다. - replace 이 옵션은 행을 중복되게 추출하는걸 허용할지를 결정합니다. replace = True ->..
일반적으로 pandas의 groupby를 이용하면 한번에 하나의 aggregate function밖에 사용할 수 없습니다. import pandas as pd dict_item = { 'date': [ 20200101, 20200102, 20200103, 20200101, 20200102, 20200103, 20200101, 20200102, 20200103, 20200101, 20200102, 20200103, 20200104 ], 'item_id': [ 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4 ], 'item_name': [ 'a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c', 'd', 'd', 'd', 'd' ], 'price': [ 1000, ..
transform method는 DataFrame에서 groupby로 집계한 결과를 동일한 index를 가진 행에 넣어서 return해줍니다.말만 들으면 무슨 소린지 잘 감이 오지 않는데 실제 예시를 봅시다. import pandas as pddict_item = { 'date': [ 20200101, 20200102, 20200103, 20200101, 20200102, 20200103, 20200101, 20200102, 20200103, 20200101, 20200102, 20200103, 20200104 ], 'item_id': [ 1, 1, 1, 2, 2, 2, 3, 3, 3, 4..
requests library와 API를 이용하다보면 csv format의 데이터를 얻어올 때가 있습니다. 그 결과값은 API를 어떻게 만드냐에 따라 달라질 수 있지만 주로 보이는 형태는 아래와 같습니다. import requests api_endpoint = 'https://test_api/get_data' response = requests.get(api_endpoint) print(response.status_code) print(response.content) print(type(response.content)) -- Result 200 b'modelno,name,price,weight\r\nAGH1341,Laptop,1300000,1200\r\nSOE1029,Desktop,1800000,3500..