import numpy as npimport pandas as pd np.random.seed(1)df = pd.DataFrame({ 'pop': np.random.randint(1, 10, 4), # 1~ 10 범위의 난수 4개 'income': np.random.randint(1, 10, 4), # 1~10 범위의 난수 4개 }, index=['a', 'b', 'c', 'd'])print(df) pop incomea 6 1b 9 2c 6 8d 1 7 # agg(aggregate): DataFrame의 축(axis)을 기준으로 통계량을 집계(aggregate)하기 위한 함수# 통계량(statistics): 합계(sum), 평균(mean), 분산(var), 표준편차(std),# 최솟값(min), 최댓값(..
apply
import numpy as npimport pandas as pd def squares(x): return x ** 2 def doubles(x): return x * 2 result1, result2 = squares(3), doubles(3)print(result1, result2)9 6 array = np.array([1, 2, 3])result1 = squares(array) # np.array ** 2result2 = doubles(array) # np.array * 2print(result1, result2)[1 4 9] [2 4 6] df = pd.DataFrame({'a': [1, 2, 3],'b': [4, 5, 6]})print(df)print(squares(df)) a b0 1 41 ..