Best Python code snippet using slash
main.py
Source:main.py
...73 end = datetime(2016, 6, 12)74 df = web.DataReader("078930.KS", "yahoo", start, end)75 con = sqlite3.connect("./kospi.db")76 df.to_sql('078930', con, if_exists='replace')77 self.print_tb(" db is writed ", str(df))78 con.close()79 @clear_textbrowser_decorator80 def on_clicked_read_sql_test(self):81 con = sqlite3.connect("./kospi.db")82 readed_df = pd.read_sql("SELECT * FROM '078930'", con, index_col='Date')83 self.print_tb(" db is readed ", str(readed_df))84 con.close()85 @clear_textbrowser_decorator86 def on_clicked_stategy_1_btn(self):87 strategy1.strategy1(self)88 @clear_textbrowser_decorator89 def on_clicked_stategy_2_btn(self):90 strategy2.strategy2(self)91 @clear_textbrowser_decorator92 def on_clicked_stategy_3_btn(self):93 strategy3.strategy3(self)94 @clear_textbrowser_decorator95 def on_clicked_df_multiple_btn(self):96 a = pd.DataFrame([[1, 2], [3, np.nan, ], [5, 6]], columns=["a", "b"])97 b = pd.DataFrame([[1, 2], [3, 4, ], [5, 6]], columns=["a", "b"]) * 1098 self.print_tb("a is ", str(a))99 self.print_tb("b is ", str(b))100 self.print_tb("a*b ", str(a*b))101 a = pd.DataFrame([[1, 2], [3, np.nan, ], [5, 6]], columns=["a", "b"])102 b = pd.DataFrame([[1, 2, 3], [3, 4, 5], [5, 6, 7]], columns=["c", "b", "d"]) * 10103 self.print_tb(" new a is ", str(a))104 self.print_tb(" new b is ", str(b))105 self.print_tb(" a*b ", str(a*b))106 return_df = pd.DataFrame(107 [108 [np.nan, np.nan, 2],109 [3, np.nan, 3],110 [5, 6, np.nan],111 ],112 columns=["ì¼ì±", "íë", "SK"]113 )114 asset_on_df = pd.DataFrame(115 [116 [0, 1],117 [0, 1],118 [1, 0],119 ],120 columns=["ì¼ì±", "SK"]121 )122 return_df123 asset_on_df124 @clear_textbrowser_decorator125 def on_clicked_make_ana_data_btn(self):126 make_ana_data(self)127 """128 # using datareader129 # samsung_df = fdr.DataReader('005390', '2017-01-01', '2017-12-31')130 # self.print_tb("8", str(samsung_df))131 df_005930 = marcap_data('2021-01-21', code='005930')132 df_005930 = df_005930.assign(Amount=df_005930['Amount'].astype('int64'),133 Marcap=df_005930['Marcap'].astype('int64'))134 self.print_tb(" df_005930 ", str(df_005930))135 """136 @clear_textbrowser_decorator137 def on_clicked_load_data_btn(self):138 """139 ë°ì´í° ë¡ë140 """141 df = pd.read_csv("data/fin_statement_new.csv")142 self.print_tb("0", str(df))143 """144 ë°ì´í° ì 리145 """146 # ìì¥ì¼ ì´ ì ê±°147 df = df.drop(["ìì¥ì¼"], axis=1)148 # rename ì´149 df = df.rename(columns={150 "DPS(ë³´íµì£¼, íê¸+주ì, ì°ê°)": "DPS",151 "P/E(Adj., FY End)": "PER",152 "P/B(Adj., FY End)": "PBR",153 "P/S(Adj., FY End)": "PSR",154 })155 """156 ì ë ¬ ë° ë°ì´í° ë¶ì157 """158 # ë
ëë¡ ì ë ¬íê³ ì´ë¦ì´ ëª ê°ì¸ì§ ì¹´ì´í¸159 self.print_tb("1", str(df.groupby(['year'])['Name'].count()))160 # ì´ë¦ì¼ë¡ ì ë ¬íê³ ëª ë
ëì ììëì§ ì¹´ì´í¸161 self.print_tb("2", str(df.groupby(['Name'])['year'].count()))162 # code or nameì ì¤ë³µ ì²´í¹ ë°©ë²1163 self.print_tb("3", str(df.groupby(['year'])['Name'].nunique().equals(df.groupby(['year'])['Code'].nunique())))164 # code or nameì ì¤ë³µ ì²´í¹ ë°©ë²2165 self.print_tb("4", str(df.groupby(['year', 'Name'])['Code'].nunique()))166 self.print_tb("5", str(df.groupby(['year', 'Name'])['Code'].nunique().nunique()))167 # index를 dfì yearë¡ íê³ / columnì dfì Name / ê°ì dfì ìì 주ê°ë¡ ì¤ì 168 yearly_price_df = df.pivot(index="year", columns="Name", values="ìì 주ê°")169 self.print_tb("6", str(yearly_price_df))170 # í í´ ììµë¥ 구í기171 yearly_rtn_df = yearly_price_df.pct_change(fill_method=None).shift(-1)172 self.print_tb("7", str(yearly_rtn_df))173 # ìì¥íì§ ì¢
목 ì²ë¦¬174 self.print_tb("8", str(yearly_price_df['AD모í°ì¤']))175 self.print_tb("9", str(yearly_price_df['AD모í°ì¤'].pct_change(fill_method=None).shift(-1)))176 # self.load_data_btn.setDisabled(True)177 def print_tb(self, print_log_name="0", msg=""):178 self.log_textBrowser.moveCursor(QtGui.QTextCursor.End)179 if print_log_name == "0":180 self.log_textBrowser.insertPlainText("\n" + msg)181 else:182 self.log_textBrowser.insertPlainText("***************" + print_log_name + " *************** : \n")183 self.log_textBrowser.insertPlainText("\n" + msg)184 self.log_textBrowser.insertPlainText("\n\n *************** " + print_log_name + " *************** - end : \n\n")185 QApplication.processEvents(QEventLoop.ExcludeUserInputEvents)186 def on_clicked_clear_tb_btn(self):187 self.log_textBrowser.clear()188app = QApplication(sys.argv)189mw = MainWindow()190mw.show()191app.exec_()
strategy1.py
Source:strategy1.py
...10 def start(self):11 """12 Load data13 """14 self.parent.print_tb(" origin df", str(self.df))15 """16 Filter17 """18 market_cap_quantile_series = self.df.groupby("year")['ìê°ì´ì¡'].quantile(.2)19 self.parent.print_tb(" ë
ëë³ ìê° ì´ì¡ íì 20%", str(market_cap_quantile_series))20 filtered_df = self.df.join(market_cap_quantile_series, on="year", how="left", rsuffix="20%_quantile")21 filtered_df = filtered_df[filtered_df['ìê°ì´ì¡'] <= filtered_df['ìê°ì´ì¡20%_quantile']]22 self.parent.print_tb(" ìê° ì´ì¡ íì 20%ë§ ë¨ê¸°ê³ íí°ë§", str(filtered_df))23 """24 Selector25 """26 # Selector - 127 filtered_df = filtered_df[filtered_df['PBR'] >= 0.2]28 self.parent.print_tb(" PBR 0.2 ì´ì íí°ë§", str(filtered_df))29 # Selector - 230 smallest_pbr_series = filtered_df.groupby("year")['PBR'].nsmallest(15)31 self.parent.print_tb(" ë
ëë³ íì 15ê° íí°ë§", str(smallest_pbr_series))32 # Selector - 333 # ìê° ì´ì¡ íì 20% + PBR 0.2 ì´ì + ë
ëë³ íì 15ê°ì index를 ë긴ë¤34 selected_index = smallest_pbr_series.index.get_level_values(1)35 selector_df = filtered_df.loc[selected_index].pivot(36 index='year', columns="Name", values="PBR"37 )38 # íí°ë§ë ë°ì´í°ë pbrì´ ë¤ì´ê°ê³ ë머ì§ë nanê° ë¤ì´ê°ë¤39 self.parent.print_tb(" selector_df", str(selector_df))40 # pbrì´ ììê²½ì° ë§¤ìíë¤ê³ ê°ì í´ì 1ë¡ ì²ë¦¬ + pbrì´ 0ì¸ ë°ì´í°ë nanë¡ ì²ë¦¬41 asset_on_df = selector_df.notna().astype(int).replace(0, np.nan)42 self.parent.print_tb(" asset_on_df", str(asset_on_df))43 selected_return_df = self.yearly_rtn_df * asset_on_df44 rtn_series, cum_rtn_series = plothelper.get_return_series(selected_return_df)...
dtest.py
Source:dtest.py
...7 lumberjack()8except IndexError:9 exc_type, exc_value, exc_traceback = sys.exc_info()10 # print("*** print_tb:")11 # dtraceback.print_tb(exc_traceback, file=sys.stdout)12 print("*** print_tb verbose 1:")13 dtraceback.print_tb(exc_traceback, file=sys.stdout, verbosity=1)14 print("*** print_tb verbose 2:")15 dtraceback.print_tb(exc_traceback, file=sys.stdout, verbosity=2)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!