TIL 123일차 : np.where을 사용하는 코드

2024. 4. 21. 14:03회고/TIL(매일)

 

✏️도전한 점


1. streamlit 학습 내용을 바탕으로 직접 웹페이지를 제작했다.

2. 학습 내용 중에 유용한 전처리 코드를 발견해서 정리했다.

 

01 전처리 : np.where을 알아보자


- np.where 함수는 조건에 따라 배열에서 요소를 선택하는 데 사용된다. NumPy의 np.where는 기본적으로 if-else 문을 벡터화한 형태로 볼 수 있다.

 

- 출력 형식은 NumPy 배열의 문자열 표현 방식 때문이다. NumPy 배열을 출력할 때, 배열 내의 숫자 타입 요소들은 콤마로 구분되어 출력되지만, 문자열 타입의 요소들은 콤마 없이 출력되며, 대괄호([]) 안에 공백으로 구분되어 나타난다. 이는 넘파이의 출력 형식에 따른 것으로, 배열의 실제 구조나 데이터를 변경하지 않는다.

02 참고코드


- streamlit 학습 영상: 데이터를 전처리하는 코드 중에서도 유용한 코드들이 있어서 캡쳐해뒀다.

 

1) 컬럼 리네이밍을 간단하게 하는 방법: df.columns

 

2) 다중 불리언 조건식 작성하는 방법: np.where

 

 

03 웹페이지 제작 과정


 

04.21 Streamlit 시각화

01 시각화 코드 import streamlit as st import pandas as pd import numpy as np import pydeck as pdk # 페이지를 session_state에 초기화 if 'page' not in st.session_state: st.session_state.page = 'home' # 페이지란 값이 없을테니 당연 hom

specialda.tistory.com

 

04 참고링크 : Docs


- Streamlit Docs를 참고하면 다양한 위젯들을 직접 만들어 볼 수 있다.

 

Streamlit Docs

Join the community Streamlit is more than just a way to make data apps, it's also a community of creators that share their apps and ideas and help each other make their work better. Please come join us on the community forum. We love to hear your questions

docs.streamlit.io

 

05 주말에 잠깐 튜터님과 함께