본문 바로가기

분류 전체보기

(102)
07_01_13. 데이터프레임 공백 제거 strip() # 양쪽 공백 제거 df['fruit'].str.strip() # 오른쪽 공백 제거 df['fruit'].str.rstrip() # 왼쪽 공백 제거 df['fruit'].str.lstrip()
07_01_12. aggregation column level down & 컬럼명 변경 ## 컬럼명 level down df_01_ag = df_01.groupby(["origin_bizpl_cd" , "goods_cd", "bizpl_goods_cd"] ).agg({"bg_purch_qty" : ["sum","mean"]}) # agg column level down df_01_ag = df_01_ag.droplevel(0, axis= 1).reset_index() ## aggregation 컬럼명 변경 df_01_ag = df_01.groupby(["origin_bizpl_cd" , "goods_cd", "bizpl_goods_cd"] ).agg({"bg_purch_qty": [("sum", "sum"), ("mean", "mean"), ("max", "max")], "bg_purch_..
07_01_12. pd.merge pd.merge( df_tmp_01, df_sch_schd[ (df_sch_schd.origin_bizpl_cd == v_biz) & (df_sch_schd.radi_unit == v_radi)] , how='left' , left_on = "oper_dt", right_on ="dt") pd.merge( df_tmp_01, df_sch_schd[ (df_sch_schd.origin_bizpl_cd == v_biz) & (df_sch_schd.radi_unit == v_radi)] , how='left' , left_on = "oper_dt", right_on ="dt", suffixes=('', '_x')
07_01_11. pickle 형태로 내보내기 / 불러오기 import pickle import pickle5 as pickle #Save with open( 'hi.pickle' , 'wb' ) as handle: pickle.dump( df, handle, protocol = pickle.HIGHEST_PROTOCOL ) #Load with open( 'hi.pickle' , 'rb' ) as handle: hi = pickle.load(handle)
07_01_10. jupyter notebook terminal에서 폴더 삭제 rm -rf /home/ec2-user/SageMaker/dain/code/data
07_01_08. seaborn x축 날짜 변경 (시계열 형태) from matplotlib import pyplot as plt #plot fig = plt.figure(figsize=(20,25)) p = sns.relplot("oper_date", "bg_purch_qty", data=df_plot, estimator=None, kind='line', col='goods_cd', col_wrap=5) x_dates = df_plot['oper_date'].dt.strftime('%y-%m').sort_values().unique() p.set_xticklabels(label=x_dates, rotation=45, ha='right') stackoverflow.com/questions/51105648/ordering-and-formatting-dates-on-x-..
07_01_07. aws 한글 폰트 지정 import matplotlib.font_manager as fm font_list = matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf') [matplotlib.font_manager.FontProperties(fname=font).get_name() for font in font_list] font_path = '/usr/share/fonts/truetype/nanum/NanumGothic.ttf' fontprop = fm.FontProperties(fname=font_path) sam_line = dat_line[ dat_line["line_cd"] == line] linenm = df_line.line_nm[ df_line[..
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] + '"')