목록Programming/Python(파이썬) (44)
59doit
▷ arr = np.arange(12.).reshape((3,4)) arr # # array([[ 0., 1., 2., 3.], # [ 4., 5., 6., 7.], # [ 8., 9., 10., 11.]]) ▷ arr[0] # # array([0., 1., 2., 3.]) arr-arr[0] # # array([[0., 0., 0., 0.], # [4., 4., 4., 4.], # [8., 8., 8., 8.]]) 각 로우별 한번씩 수행 ▷ frame = pd.DataFrame(np.arange(12.).reshape((4,3)), columns=list('bda'), index=['Utah','Ohio','Texas','Oregon']) series = frame.iloc[0] frame # # b ..
ser ser = pd.Series(np.arange(3.)) ser # # 0 0.0 # 1 1.0 # 2 2.0 # dtype: float64 ▷ 정수 기반의 색인을 사용하지 않는 경우 이런 모호함은 사라진다. ser2 = pd.Series(np.arange(3.), index=['a', 'b', 'c']) ser2[-1] # 2.0 ▷ 일관성 유지를 위해 정수값을 담고 있는 축 색인이 있다면 우선적으로 라벨을 먼저 찾아보도록 구현되어 있다. ser[:1] # # 0 0.0 # dtype: float64 ▷ 라벨 컬럼 => loc 을 사용 ser.loc[:1] # # 0 0.0 # 1 1.0 # dtype: float64 ▷ 정수 색인 row =>iloc 을 사용 ser.iloc[:1] # # 0 0..
drop ▷ obj = pd.Series(np.arange(5.), index=['a', 'b', 'c', 'd', 'e']) obj # # a 0.0 # b 1.0 # c 2.0 # d 3.0 # e 4.0 # dtype: float64 new_obj = obj.drop('c') new_obj # # a 0.0 # b 1.0 # d 3.0 # e 4.0 # dtype: float64 obj.drop(['d', 'c']) # # a 0.0 # b 1.0 # e 4.0 # dtype: float64 ▷ 데이터 프레임만들기 data = pd.DataFrame(np.arange(16).reshape((4,4)), index =['Ohio','Colorado','Utah','New York'],columns=[..
index import pandas as pd import numpy as np ▷ obj = pd.Series(range(3),index=['a','b','c']) index = obj.index index # Index(['a', 'b', 'c'], dtype='object') index[1:] # Index(['b', 'c'], dtype='object') ▷ 인덱스 안의 인덱스 변경은 불가 Error index[1] = 'd' # # TypeError: Index does not support mutable operationserror ▷ 인덱스 컬럼명을 범위값으로 지정하고 index가 있는지확인 is & in is labels = pd.Index(np.arange(3)) labels # Int6..