[파이썬] pandas 컬럼이 null 이면 다른 컬럼값 변경
Column의 값이 null 일 때, 다른 Column의 값을 변경하고자 합니다. import pandas as pd import numpy as np raw_data = {'age': ['101', '105', '103', '107','108', np.nan,'110','111','112','113'], 'check': ['', '', '', '', '', '', '', '', '', '']} df = pd.DataFrame(raw_data) df 중간에 Null 값이 있는 것을 확인할 수 있습니다. age값이 null 일 때, check Column의 값을 변경하고자 한다면 df.loc[df['age'].isna(), 'check'] = 0
2022. 9. 22.
[파이썬] pygame 으로 원 그리기
import pygame pygame.init() BLACK = (0, 0, 0) WHITE = (255, 255, 255) BLUE = (0, 0, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) screensize = [400, 300] screen = pygame.display.set_mode(screensize) pygame.display.set_caption("Drawing Rectangle") done = False clock = pygame.time.Clock() while not done: clock.tick(10) for event in pygame.event.get(): if event.type == pygame.QUIT: done=True screen.fi..
2022. 9. 20.
[파이썬] 배열에서 항목(중복제거) 찾고 Count 하기
np.unique를 사용해서 배열 중에 항목(중복제거)을 찾고, 이 항목들의 수를 세는 방법입니다. import numpy as np lst = [1 , 2 , 3 , 9 , 10 , 2 , 2 , 3 , 3 , 1 , 1 ] n_lst = np.array(lst) # 배열을 numpy 배열로 변환 u, c = np.unique(n_lst, return_counts=True) # np.unique 함수 사용 print(u, c) # 참조용 : 유니크한 값, 유니크한 값의 수 print(len(u)) # 몇개의 클래스인지 출력
2022. 9. 18.