본문 바로가기

728x90
반응형
SMALL

데이터프레임

(3)
[Python] 23. pandas DataFrame MultiIndex column : levels, get_level_values(),pd.MultiIndex.from_product()예제 import pandas as pd import numpy as np import matplotlib.pyplot as plt from matplotlib import rc import matplotlib rc('font', family='AppleGothic') plt.rcParams['axes.unicode_minus'] = False data = np.random.randint(1,10, size=4) data array([2, 9, 5, 7]) data = np.random.randint(30,101, size=(4,6) ) data array([[94, 42, 91, 67, 54, 94], [87, 30, 83, 31, 92, 65], [83, 43, 99, 43, 37, 59], [82, 88..
[Python] 11. pandas DataFrame 인덱싱(Indexing), 슬라이싱(Slicing) 예제 import pandas as pd import numpy as np data = {'eng':[10,30,50,70], 'kor':[20,40,60,80], 'math':[90,50,20,70]} df = pd.DataFrame(data, index=['a','b','c','d'] ) df # df['a'] # df['컬럼명'] df['eng'] [OUT] : a 10 b 30 c 50 d 70 Name: eng, dtype: int64 df[['eng','math']] df['eng']['a':'c'] [OUT] : a 10 b 30 c 50 Name: eng, dtype: int64 df[['eng']] # df[슬라이싱(row)] df[1:3] df df['b':'c'] iloc 인덱싱 슬라이싱(..
[Python] 01. pandas Series 만들기 : pd.Series()예제 import pandas as pd import numpy as np # 1차원 데이터 myList = [10,20,30,40] # 리스트 t = (10,20,30,40) # 튜플 d = {'aa':10,'bb':20,'cc':30} # 딕셔너리 판다스의 핵심 Series : 1차원데이터 DataFrame : 2차원데이터(이상) 시리즈 예제 sr1 = pd.Series(myList,index=['aa','bb','cc','dd'], dtype=np.int32, name='kor' ) sr1 [OUT] : aa 10 bb 20 cc 30 dd 40 Name: kor, dtype: int32 sr2 = pd.Series(t) sr2 [OUT] : 0 10 1 20 2 30 3 40 dtype: int64 s..

728x90
반응형
LIST