반응형 파이썬8 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. pyqt selenium 채권 정보 크롤링 (3): python활용한 채권 데이터 크롤링 구현 라이브러리 불러오기 from selenium import webdriver from selenium.webdriver.chrome.options import Options # 옵션 from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys import requests from bs4 import BeautifulSoup import pandas as pd 셀레니움 사용을 위해 selenium 및 reque.. 2023. 7. 3. 이전 1 2 다음 반응형