언어 꿀Tip (87) 썸네일형 리스트형 07_01_06. multi columns flatten ex) pd.pivot_table https://stackoverflow.com/questions/39273441/flatten-pandas-pivot-table Flatten pandas pivot table This is a follow up of my question. Rather than a pivot table, is it possible to flatten table to look like the following: data = {'year': ['2016', '2016', '2015', '2014', '2013'], 'country':[... stackoverflow.com df_test_01 = pd.pivot_table( df_test , index =['part_datecd'] , columns='good_cls1cd'.. 07_01_09. index filtering df_sum_qty_01 = df_sum_qty_01[np.in1d( df_sum_qty_01.index.get_level_values(1), line )] (인덱스 filter) 07-01-05. [ ]없이 list string ', '.join( '"' + pd.Series(z) + '"') # 여기서 z는 리스트임! ', '.join( '"' + df_holi[~df_holi.holiday_nm.isnull()]['holiday_nm'].iloc[0:10] + '"') 07-01-04. 엑셀파일 저장하기 in python 1. 한개시트를 엑셀파일로 저장 filename = "D:\\김민영\\01_1.편의점\\FF자동발주\\'21년 데이터 탐색\\202012_상품선별 위한 14개 점포 분류별 탐색\\20201229_stk_turnover_zero.xlsx" data_dw_02.to_excel(filename) 2. 시트별 저장하기 filename = "D:\\김민영\\01_1.편의점\\FF자동발주\\'21년 데이터 탐색\\202012_상품선별 위한 14개 점포 분류별 탐색\\20210104_1912_goods비율.xlsx" # 엑셀파일 열기 writer = pd.ExcelWriter( filename , engin = "xlsxwriter") # 시트별 데이터 추가 df_19_01_pv.to_excel( writer, sh.. 07-01-03. sql row_number 와 동일한 함수 df['row_num'] = df.sort_values(['id', 'msg_ts'], ascending=True).groupby(['id', 'topic']).cumcount() + 1 07-01-02. 데이터프레임 컬럼값 포함 in 함수 isin # 소분류별 판매량 집계 sam_dat = t_dat[~t_dat.line_cd.isin(['01','02','03','04'])] # in 함수 # df.line_cd.isin(['01', '02']) # df[df.line_cd.isin([])) # not in 함수 # ~df.line_cd.isin[] 07_01_01. pandas groupby ### data aggretation dat_class2 = dat.groupby(["origin_bizpl_cd", "oper_dt", "line_class_cd", "line_class_nm"], as_index=False)["p_buy_sale_qty","p_buyget_sale_qty"].agg(["sum", "mean"]) dat_class2 = dat.groupby(['yyyymm', 'origin_bizpl_cd']).agg( {"buyget_sale_qty": 'sum', 'buy_sale_qty': ['sum', 'mean']} ) dat_class2.reset_index(drop=False) # 데이터 프레임 index 앞에 숫자 제외하는 것! dat_class2.reset_index(.. 이전 1 ··· 6 7 8 9 다음