我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用tushare.get_report_data()。
def get_basic(): hsdq = stock_info.ix['300141'] print hsdq report = ts.get_report_data(2014, 1) print report #hsdq=stock_info.ix['300141'] #print hsdq #report=ts.get_report_data(2014,1) #print report print '*' * 20 df = ts.get_today_all() zrkj = df[df['code'] == '300333'] print type(zrkj) print type(zrkj['code']) print zrkj['name'].values[0]
def __init__(self): self.name = "base" self.fundaLib = {} self.fundaLib[fundaType.performance] = funda_cell(ts.get_report_data, "performance_report") self.fundaLib[fundaType.profit] = funda_cell(ts.get_profit_data, "profit_report") self.fundaLib[fundaType.operation] = funda_cell(ts.get_operation_data, "operation_report") self.fundaLib[fundaType.growth] = funda_cell(ts.get_growth_data, "growth_report") self.fundaLib[fundaType.debtpaying] = funda_cell(ts.get_debtpaying_data, "debtpaying_report") self.fundaLib[fundaType.cashflow] = funda_cell(ts.get_cashflow_data, "cashflow_report")
def profit(self): df_2016=ts.get_report_data(2016,4) #???????? #df= df.sort_values('profits_yoy',ascending=False) #df.to_excel('profit.xls') df_2015=ts.get_report_data(2015,4) df_2016.to_excel('2016_report.xls') df_2015.to_excel('2015_report.xls') code_2015_lost=df_2015[df_2015['net_profits']<0]['code'].values code_2016_lost=df_2016[df_2016['net_profits']<0]['code'].values print code_2015_lost print code_2016_lost two_year_lost=[] #two_year_lost_name=[] for i in code_2015_lost: if i in code_2016_lost: print i, #name=self.base[self.base['code']==i].values[0] two_year_lost.append(i) self.saveList(two_year_lost,'st_dangours.csv') #df_2014=ts.get_report_data(2014,4)
def get_report_data(year, quarter): ''' invoke tushare get_report_data() with csv output brief: to improve data integrality, we repeatedly do these actions in a row, call API -> append to file -> drop duplicates args: year, quarter returns: csv format data containing the whole martket report in specific year, quarter json fomat, df.to_json(year+'q'+quarter+'.json', orient='index') ''' # profit print "[%s] profit %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter) filename = PREFIX + '/' + year + 'q' + quarter + '.profit.csv' df = ts.get_profit_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates() print "\n" save_to_file(filename, df) # operation print "[%s] operation %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter) filename = PREFIX + '/' + year + 'q' + quarter + '.operation.csv' df = ts.get_operation_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates() print "\n" save_to_file(filename, df) # growth print "[%s] growth %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter) filename = PREFIX + '/' + year + 'q' + quarter + '.growth.csv' df = ts.get_growth_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates() print "\n" save_to_file(filename, df) # debtpaying print "[%s] debtpaying %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter) filename = PREFIX + '/' + year + 'q' + quarter + '.debtpaying.csv' df = ts.get_debtpaying_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates() print "\n" save_to_file(filename, df) # cashflow print "[%s] cashflow %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter) filename = PREFIX + '/' + year + 'q' + quarter + '.cashflow.csv' df = ts.get_cashflow_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates() print "\n" save_to_file(filename, df) # main report print "[%s] main %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter) filename = PREFIX + '/' + year + 'q' + quarter + '.csv' df = ts.get_report_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates() print "\n" return save_to_file(filename, df)