[pandas] 데이터 재구조화 : melt()
Pandas 모듈의 melt() 함수는 ID변수 컬럼을 기준으로 다른 컬럼들을 데이터에 녹여내는 것이다. 즉, 컬럼명을 데이터에 녹이는 것이라고 생각하면 쉽다. 문법 pd.melt( 테이블명, id_vars = 기준 컬럼 , value_vars = 녹여낼 컬럼 ) 또는 테이블명.melt( id_vars = 기준 컬럼 , value_vars = 녹여낼 컬럼 ) 우선, 설명을 위해 임의의 데이터프레임을 만듭니다. import pandas as pd dict = {} dict['class_no'] = ['001','002','003','004'] dict['class'] = ['A','B','C','D'] dict['male_child'] = [1,2,3,4] dict['male_adult'] = [5,6,7..
[나도코딩] 파이썬 강의_퀴즈4
[내가 쓴 코드] from random import * command = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] #조건 1 shuffle(command) #조건2 chicken = sample(command,1) command = set(command) command.remove(chicken) coffee = sample(command,3) print(''' -- 당청자 발표 --- 치킨 당첨자 : '''+chicken+''' 커피 당첨자 : '''+coffee+''' -- 축하합니다 --''') [에러 문구] Traceback (most recent call last): File "c:\Users\ejcej\Desktop\python tutori..