본문 바로가기
반응형

PYTHON9

[python] 직관적으로 cumulative count 계산하기(ft. pandas, numpy) 어떤 카테고리 내에서 시간 순으로 나열되어 있는 데이터에서, 특정 신호 전까지 누적카운트를 쭉 나열하는 방법을 생각해볼 수 있다. 망상해본 것이다.(원래 망상하면서 이것 저것 구현해봐야 한다.) 오늘은 이와 비슷한? 학년-반 내에서 학생 번호가 쭉 있을 때, 결석 전까지 누적 count를 매겨보려고 한다. 글로만 보면 이해안가니까 바로 코드로 deep dive! 1. Library오늘은 numpy, pandas 이외에 dictionary를 편하게 쓸 defaultdict 빌트인 함수를 가져온다.from collections import defaultdictimport numpy as npimport pandas as pd 2. Data대충 알겠지 않는가? 5,6학년 내에 1,2,3반이 있는데 각 8번.. 2025. 3. 19.
explode의 이해: Pandas dataframe에서 list 원소를 펼치는 방법 데이터프레임 전처리를 하다 보면, 가끔 아래처럼 grade별로 number가 list로 묶여있는 데이터를 마주하게 된다.data = {'grade': [1, 2, 3], 'number': [[10, 20], [30], [40, 50, 60]]}df = pd.DataFrame(data)### grade number0 1 [10, 20]1 2 [30]2 3 [40, 50, 60]### 이런 경험이 없으면, long form으로 쫙 펼쳐서 보고 싶은데 참 난감하다. 이 경우 pandas에서는 어떻게 쉽게 해결할 수 있는지, 그리고 그것을 구현해 보는 시간을 갖도록 한다.(직접 해보는 이유는, 단순히 method 하나 들고와서 "띡" 해결하는 것이 아닌 처리 로직을 이해하기 위함이다.) 1. .. 2025. 3. 9.
Fast API Tutorial(3.5): toy project(calculator) Fast API의 기능을 간단히 익힌 상태에서, API와 python으로 간단히 웹을 만들 수 있는 streamlit을 이용해 간단한 계산기를 만들어 보자api.py: Fast api 모듈 calculator.py: 계산기 모듈 streamlit_app.py: streamlit 모듈 main.py: Fast api와 streamlit을 실행하는 메인 모듈 우리는 streamlit을 통해 웹 화면에서 x, y 두 float 값과 operator(+, -, /, *)를 입력 -> 입력된 값이 api를 통해 결과를 반환 -> 반환된 결과가 다시 streamlit 웹 화면에 게시되도록 할 예정이다. 1. Fast API이 부분에서는 API 통신을 통해 계산기 인자를 받아 결과를 뱉어내도록 만드는 것이 목표다.1.. 2024. 3. 1.
Fast API Tutorial(3): query parameters 전체 코드 from fastapi import FastAPI from enum import Enum from typing import Optional app = FastAPI() @app.get("/", description='this is our first roote') async def base_get_roote(): return {"message":"hello world"} @app.post("/") async def post(): return {"message":"hello from the post roote"} @app.put("/") async def put(): return {"message":"hello from the put roote"} @app.get("/users") async de.. 2024. 2. 24.
Fast API Tutorial(2): path parameters 전체 코드 from fastapi import FastAPI from enum import Enum app = FastAPI() @app.get("/", description='this is our first roote') async def base_get_roote(): return {"message":"hello world"} @app.post("/") async def post(): return {"message":"hello from the post roote"} @app.put("/") async def put(): return {"message":"hello from the put roote"} @app.get("/users") async def list_users(): return {"mes.. 2024. 2. 23.
Fast API Tutorial(1): introduction api 공부 기록 환경 설정 requirements.txt 파일 작성 fastapi uvicorn[standard] 실습 "message":"hellow world" 터미널에서 호출 방법: univocorn main:app from fastapi import FastAPI app = FastAPI() @app.get("/") async def root(): return {"message":"hello world"} main:app의 의미 - main.py에서의 main - app = FatAPI(), @app에서의 app 만약 main.py를 hello.py로 변경 & app명칭을 world로 변경하면? uvicorn hello:world처럼 입력하면 됨 다시 돌아와서, uvicorn main:app을 .. 2024. 2. 23.
반응형