You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.5 KiB
59 lines
1.5 KiB
3 years ago
|
|
||
|
import pandas as pd
|
||
|
|
||
|
|
||
|
export_cols_bs = {
|
||
|
'存货' : 'INVENTORIES',
|
||
|
'负债合计' : 'TOT_LIAB',
|
||
|
'流动资产合计' : 'TOT_CUR_ASSETS'
|
||
|
}
|
||
|
|
||
|
export_cols_pl = {
|
||
|
'净利润' : 'NET_PROFIT_INCL_MIN_INT_INC',
|
||
|
'营业外收入' : 'PLUS_NON_OPER_REV',
|
||
|
'营业收入' : 'OPER_REV'
|
||
|
}
|
||
|
|
||
|
def adj_split(df):
|
||
|
df.reset_index(inplace=True)
|
||
|
|
||
|
df_ori = df[df['截止日'] == df['数据报告期']]
|
||
|
df_adj = df[df['截止日'] != df['数据报告期']]
|
||
|
return df_ori, df_adj
|
||
|
|
||
|
|
||
|
def to_qlib_format_pl(df):
|
||
|
index_cols = ['截止日', '数据报告期', '公布日']
|
||
|
sel_cols = index_cols + export_cols_pl
|
||
|
|
||
|
df_export = df[sel_cols]
|
||
|
df_export.set_index(index_cols, inplace=True)
|
||
|
|
||
|
df_export_ori, df_export_adj = adj_split(df_export)
|
||
|
df_export_ori.set_index(index_cols, inplace=True)
|
||
|
df_export_adj.set_index(index_cols, inplace=True)
|
||
|
|
||
|
adj_col_rename = {name : name+'(调整)' for name in export_cols_pl.keys()}
|
||
|
df_export_adj.rename(columns=adj_col_rename, inplace=True)
|
||
|
|
||
|
df_list = []
|
||
|
|
||
|
def _T(df, df_list):
|
||
|
for col in list(df.columns):
|
||
|
df_tmp = df[[col]].copy(deep=True)
|
||
|
df_tmp['field'] = col
|
||
|
df_tmp.rename(columns={col:'value'}, inplace=True)
|
||
|
df_list.append(df_tmp)
|
||
|
|
||
|
_T(df_export_adj, df_list)
|
||
|
_T(df_export_ori, df_list)
|
||
|
|
||
|
df = pd.concat(df_list, axis=0)
|
||
|
|
||
|
return df
|
||
|
|
||
|
|
||
|
def single_quarter(df):
|
||
|
DataFrame.sort_values(by, axis=0, ascending=True, inplace=False)
|
||
|
|