请 [注册] 或 [登录]  | 返回主站

量化交易吧 /  量化平台 帖子:3365810 新帖:17

通过单季净利计算所有季度净利润

大师做交易发表于:5 月 10 日 01:04回复(1)

手动输出所有的季报列表

season_all=['2005q1','2005q2','2005q3','2005q4',
'2006q1','2006q2','2006q3','2006q4',
'2007q1','2007q2','2007q3','2007q4',
'2008q1','2008q2','2008q3','2008q4',
'2009q1','2009q2','2009q3','2009q4',
'2010q1','2010q2','2010q3','2010q4',
'2011q1','2011q2','2011q3','2011q4',
'2012q1','2012q2','2012q3','2012q4',
'2013q1','2013q2','2013q3','2013q4',
'2014q1','2014q2','2014q3','2014q4',
'2015q1','2015q2','2015q3','2015q4',
'2016q1','2016q2','2016q3','2016q4',
'2017q1','2017q2','2017q3','2017q4',
'2018q1','2018q2','2018q3']
q1=['2005q1','2006q1','2007q1','2008q1','2009q1','2010q1','2011q1',
'2012q1','2013q1''2014q1','2015q1','2016q1','2017q1','2018q1']
q2=['2005q2','2006q2','2007q2','2008q2','2009q2','2010q2','2011q2',
'2012q2','2013q2''2014q2','2015q2','2016q2','2017q2','2018q2']
q3=['2005q3','2006q3','2007q3','2008q3','2009q3','2010q3','2011q3',
'2012q3','2013q3''2014q3','2015q3','2016q3','2017q3','2018q3']
q4=['2005q4','2006q4','2007q4','2008q4','2009q4','2010q4','2011q4',
'2012q4','2013q4''2014q4','2015q4','2016q4','2017q4']

得到所有单季度的净利润

all_single_investment=get_fundamentals(query(valuation.code))
for i in season_all:
df = get_fundamentals(query(
valuation.code,income.np_parent_company_owners
), statDate=i)
df.columns=(['code',i])
all_single_investment=pd.merge(all_single_investment,df,on='code')

对单季度净利润进行处理,得到所有季度的净利润

all_investment=pd.DataFrame()
all_investment['code']=all_single_investment['code']
for i in season_all:
if i in q1:
all_investment[i]=all_single_investment[i]
elif i in q2:
all_investment[i]=all_single_investment[i] all_single_investment[season_all[(season_all.index(i)-1)]]
elif i in q3:
all_investment[i]=all_single_investment[i] all_single_investment[season_all[(season_all.index(i)-1)]] all_single_investment[season_all[(season_all.index(i)-2)]]
else:
all_investment[i]=all_single_investment[i] all_single_investment[season_all[(season_all.index(i)-1)]] all_single_investment[season_all[(season_all.index(i)-2)]] all_single_investment[season_all[(season_all.index(i)-3)]]

import datetime
from jqdata import *
import pandas as pd
from six import StringIO
#手动输出所有的季报列表
season_all=['2005q1','2005q2','2005q3','2005q4',
            '2006q1','2006q2','2006q3','2006q4',
            '2007q1','2007q2','2007q3','2007q4',
            '2008q1','2008q2','2008q3','2008q4',
            '2009q1','2009q2','2009q3','2009q4',
            '2010q1','2010q2','2010q3','2010q4',
            '2011q1','2011q2','2011q3','2011q4',
            '2012q1','2012q2','2012q3','2012q4',
            '2013q1','2013q2','2013q3','2013q4',
            '2014q1','2014q2','2014q3','2014q4',
            '2015q1','2015q2','2015q3','2015q4',
            '2016q1','2016q2','2016q3','2016q4',
            '2017q1','2017q2','2017q3','2017q4',
            '2018q1','2018q2','2018q3']
q1=['2005q1','2006q1','2007q1','2008q1','2009q1','2010q1','2011q1',
    '2012q1','2013q1''2014q1','2015q1','2016q1','2017q1','2018q1']
q2=['2005q2','2006q2','2007q2','2008q2','2009q2','2010q2','2011q2',
    '2012q2','2013q2''2014q2','2015q2','2016q2','2017q2','2018q2']
q3=['2005q3','2006q3','2007q3','2008q3','2009q3','2010q3','2011q3',
    '2012q3','2013q3''2014q3','2015q3','2016q3','2017q3','2018q3']
q4=['2005q4','2006q4','2007q4','2008q4','2009q4','2010q4','2011q4',
    '2012q4','2013q4''2014q4','2015q4','2016q4','2017q4']
#得到所有单季度的净利润
all_single_investment=get_fundamentals(query(valuation.code))
for i in season_all:
    df = get_fundamentals(query(
               valuation.code,income.np_parent_company_owners
             ), statDate=i)
    df.columns=(['code',i])
    all_single_investment=pd.merge(all_single_investment,df,on='code')
all_single_investment
code 2005q1 2005q2 2005q3 2005q4 2006q1 2006q2 2006q3 2006q4 2007q1 ... 2016q2 2016q3 2016q4 2017q1 2017q2 2017q3 2017q4 2018q1 2018q2 2018q3
0 000001.XSHE 1.541264e+08 3.708389e+06 1.589363e+08 -5.541549e+07 2.331836e+08 2.304371e+08 4.266749e+08 4.126109e+08 5.350836e+08 ... 6.206000e+09 6.427000e+09 3.880000e+09 6.214000e+09 6.340000e+09 6.599000e+09 4.036000e+09 6.595000e+09 6.777000e+09 7.084000e+09
1 000002.XSHE 2.519146e+08 5.431379e+08 7.674057e+07 4.785697e+08 4.102369e+08 8.603418e+08 1.827909e+08 8.445142e+08 6.123493e+08 ... 4.518077e+09 2.911071e+09 1.276022e+10 6.954116e+08 6.607312e+09 3.788277e+09 1.696081e+10 8.948780e+08 8.228865e+09 4.860817e+09
2 000004.XSHE -1.313875e+06 -9.642525e+05 -2.788494e+06 -8.510388e+06 1.726932e+05 -1.866560e+06 -2.474797e+06 4.867559e+06 1.036046e+05 ... 5.378206e+06 1.171281e+07 2.460078e+07 -1.177969e+06 -2.594105e+06 -1.662184e+06 1.400098e+07 2.060513e+06 -7.668759e+04 -4.575575e+06
3 000005.XSHE -6.646618e+06 -8.223970e+06 -9.933856e+06 -1.551656e+08 5.914588e+07 8.962291e+06 4.981955e+06 -1.380445e+08 3.984999e+07 ... 1.337821e+08 6.791386e+06 -2.511203e+07 -1.014027e+07 -7.617020e+06 1.543986e+06 3.152174e+07 1.614733e+07 -8.000634e+06 -1.614740e+06
4 000006.XSHE 1.584547e+07 -1.439711e+07 2.251289e+07 8.723009e+07 3.512168e+07 1.355103e+08 7.957719e+06 3.766638e+07 1.365658e+07 ... 5.327691e+07 1.239763e+07 6.640980e+08 1.038588e+08 1.457477e+08 8.953035e+07 4.664996e+08 2.862077e+08 1.297610e+08 8.727141e+07
5 000007.XSHE 1.434639e+07 -9.430307e+06 -1.440824e+07 1.778775e+07 -4.945542e+06 -3.633892e+06 -1.380985e+07 -1.002985e+08 -9.708945e+06 ... -3.432950e+07 6.603750e+06 6.063124e+07 2.768926e+05 2.076721e+07 -1.071619e+07 6.125741e+06 -7.734863e+06 -3.332488e+06 2.406713e+06
6 000008.XSHE 4.858818e+05 -2.059888e+05 -3.005786e+06 -2.540483e+06 -9.962368e+04 -3.591172e+05 -1.691210e+05 -1.128197e+06 1.003699e+06 ... 3.034667e+07 1.749587e+08 3.049683e+08 9.341214e+06 4.638816e+07 6.619523e+07 7.518559e+08 1.052420e+07 5.085597e+07 6.218074e+07
7 000009.XSHE 6.440638e+06 2.218481e+06 1.427395e+06 6.171786e+07 2.233326e+06 -4.631729e+05 -3.153036e+06 1.370169e+08 4.374439e+07 ... 4.237742e+07 1.378489e+08 2.301840e+07 3.347200e+07 4.661009e+07 1.003969e+08 -4.727517e+07 3.523360e+07 7.967616e+07 -1.630068e+07
8 000010.XSHE -6.942886e+06 -3.067545e+06 -2.623434e+06 -6.865737e+07 -3.949511e+05 -1.629041e+07 -1.502850e+06 2.234852e+07 -1.551734e+06 ... 5.902909e+07 -4.375564e+06 1.793026e+07 -2.550807e+07 -2.005220e+07 5.824663e+07 -1.074113e+09 -4.656447e+07 -3.842158e+07 -1.069793e+08
9 000011.XSHE 1.294140e+05 1.496203e+07 1.501176e+07 4.831655e+07 -7.920714e+06 -1.163899e+07 -1.409564e+07 -1.143728e+07 -5.965495e+06 ... -5.825730e+06 -1.953781e+06 3.620597e+08 3.015978e+08 6.275796e+07 2.118109e+08 4.679609e+07 5.345682e+07 2.951570e+07 6.121616e+07
10 000012.XSHE 5.377536e+07 9.618861e+07 9.693678e+07 6.951079e+07 4.947478e+07 1.019947e+08 1.037960e+08 7.984525e+07 5.479121e+07 ... 2.620478e+08 2.480161e+08 8.282226e+07 1.701309e+08 2.228612e+08 3.180192e+08 1.143769e+08 1.593828e+08 1.934543e+08 1.162792e+08
11 000014.XSHE 8.240377e+06 1.540027e+07 3.309981e+06 4.588632e+06 2.049534e+07 2.280700e+07 2.806253e+06 -1.206747e+07 -3.402781e+06 ... -5.599933e+06 -7.087185e+06 4.613302e+07 -3.359943e+06 7.306936e+06 4.998412e+05 3.183499e+06 3.141992e+06 -5.861745e+04 -8.187584e+05
12 000016.XSHE 2.054101e+07 2.807392e+06 1.150536e+07 3.704518e+07 2.425959e+07 5.465389e+06 8.718106e+06 5.833182e+07 2.625888e+07 ... 4.405187e+06 -5.716570e+07 1.400040e+08 2.624535e+07 4.625914e+06 9.797448e+07 4.928179e+09 5.575830e+07 2.860347e+08 8.804165e+07
13 000017.XSHE -3.134084e+06 2.594418e+06 2.803802e+07 -2.375962e+07 -1.930796e+06 -7.786625e+06 3.411754e+05 -2.636336e+06 3.499745e+07 ... 3.020007e+05 1.632212e+06 5.230693e+05 2.123222e+05 -1.903701e+06 3.278666e+05 2.893099e+06 2.319832e+05 3.221788e+05 5.305139e+05
14 000018.XSHE -3.520581e+06 -2.306323e+06 -1.213484e+07 -1.948225e+07 -4.078316e+06 -5.574715e+06 -1.155290e+07 5.019858e+07 -2.397447e+07 ... 1.257121e+08 1.008666e+08 1.704959e+08 9.902958e+07 1.695769e+08 1.418544e+08 -3.036982e+07 2.185236e+08 -7.452417e+07 -1.185168e+08
15 000019.XSHE 2.530620e+05 1.562132e+06 2.447488e+06 1.277178e+06 2.606646e+06 3.985222e+06 1.356202e+05 2.734737e+07 7.204188e+05 ... -8.916119e+06 -1.245983e+07 1.241797e+08 -9.918007e+06 -7.841770e+06 -8.629219e+06 -2.770514e+07 -1.081728e+07 -7.429364e+06 -1.172758e+07
16 000020.XSHE -7.114198e+05 1.115796e+06 3.241733e+06 2.976198e+06 5.677972e+05 2.285800e+03 7.914034e+05 -2.455759e+07 1.189196e+05 ... 6.803020e+06 -2.763588e+06 9.483418e+05 4.211734e+05 1.725299e+06 -1.798083e+06 6.260199e+05 3.073679e+05 2.485766e+06 -2.500880e+06
17 000021.XSHE 7.001783e+07 8.037478e+07 7.813124e+07 8.682230e+07 8.265069e+07 8.384174e+07 8.413780e+07 8.244543e+07 3.780935e+08 ... 6.651172e+07 8.599645e+07 -8.910962e+07 1.167247e+08 1.907148e+08 1.615668e+08 7.229673e+07 8.543130e+07 8.634691e+07 2.690574e+08
18 000022.XSHE 1.749109e+08 1.807370e+08 1.641263e+08 6.367844e+07 1.513826e+08 1.709893e+08 1.756276e+08 1.288367e+08 1.423905e+08 ... 1.453145e+08 1.607047e+08 1.051362e+08 1.388445e+08 1.375633e+08 1.643620e+08 6.407167e+07 1.466621e+08 1.693982e+08 1.371567e+08
19 000023.XSHE -3.162538e+06 2.197672e+06 -4.952158e+06 -2.254894e+07 -8.164710e+06 2.509541e+06 1.237407e+07 2.157220e+07 1.918636e+07 ... 8.180492e+06 5.081922e+05 1.684397e+06 1.053154e+07 8.648410e+06 1.466921e+07 -3.348382e+06 -4.863627e+06 5.728103e+06 9.770346e+06
20 000025.XSHE -5.458717e+05 9.554596e+05 2.036082e+06 3.230635e+06 7.208649e+05 1.629205e+06 3.124519e+06 -9.343183e+07 -2.343322e+06 ... 1.158580e+07 8.467387e+06 9.782228e+05 4.494980e+06 2.010192e+07 1.600773e+07 2.625813e+07 1.610153e+07 1.081875e+07 8.920175e+06
21 000026.XSHE 7.530122e+05 4.456627e+06 4.091940e+06 6.705420e+06 4.878556e+06 8.306786e+06 6.924318e+06 1.039982e+07 1.204859e+07 ... 3.326167e+07 4.798884e+07 2.341414e+06 4.531903e+07 4.138980e+07 4.983923e+07 3.668206e+06 5.951800e+07 5.284992e+07 5.029317e+07
22 000027.XSHE 1.411225e+08 1.477074e+08 1.449044e+08 3.190854e+08 1.356698e+08 1.654442e+08 1.873076e+08 8.730634e+08 2.021471e+08 ... 6.480509e+08 4.857641e+08 9.135548e+06 1.122654e+08 2.910457e+08 4.003827e+08 -5.435566e+07 6.077366e+07 4.762632e+08 6.682613e+07
23 000028.XSHE 1.119049e+07 8.109796e+06 8.066769e+06 8.398281e+06 2.101677e+07 2.202695e+07 2.494895e+07 1.223183e+07 2.609837e+07 ... 3.430946e+08 1.806902e+08 4.637896e+08 2.725643e+08 2.835610e+08 2.469780e+08 2.546886e+08 2.927317e+08 3.489953e+08 2.852445e+08
24 000029.XSHE -1.400056e+07 -1.777556e+06 2.117202e+07 6.706298e+06 3.974322e+06 5.040780e+06 3.898224e+06 7.237044e+06 4.189687e+05 ... 1.036227e+08 1.021140e+08 7.469226e+07 3.462155e+07 1.026050e+08 1.235633e+07 3.540558e+07 -5.982685e+06 3.350488e+08 4.493428e+07
25 000030.XSHE -7.108612e+06 -9.737494e+06 -2.916624e+06 -3.741904e+07 -7.081633e+06 -9.989524e+05 2.331575e+07 -3.475923e+04 -7.381456e+06 ... 2.124646e+08 1.499479e+08 1.575862e+08 2.210649e+08 2.323749e+08 1.911180e+08 1.869898e+08 2.292156e+08 2.521984e+08 1.797025e+08
26 000031.XSHE 2.363820e+07 5.286603e+07 1.848987e+07 1.807964e+07 2.385845e+07 5.347373e+07 1.898434e+07 6.890326e+07 1.407977e+07 ... -2.953635e+07 -8.421379e+07 6.434294e+08 1.427441e+08 1.255681e+07 3.706259e+08 4.194043e+08 2.575961e+08 3.664717e+08 2.840367e+08
27 000032.XSHE 1.369459e+07 9.831543e+06 7.223966e+06 9.300623e+06 7.920416e+06 1.338522e+07 8.221387e+06 1.228199e+07 1.144442e+07 ... 2.113949e+07 1.874756e+07 3.635582e+06 1.018234e+07 1.519142e+07 1.965003e+07 -1.865215e+07 2.550041e+07 3.494034e+07 2.305791e+07
28 000034.XSHE -1.576038e+07 -2.688590e+07 -1.229603e+07 -1.311059e+08 -1.420634e+07 -1.419437e+07 1.192549e+07 -1.056114e+08 -5.995370e+06 ... 2.577557e+08 8.198823e+07 6.997028e+07 8.526205e+07 1.185589e+08 1.088904e+08 4.102134e+08 1.114069e+08 1.560925e+08 7.689715e+07
29 000035.XSHE -3.298159e+06 -2.783062e+07 5.262987e+06 -9.667350e+07 -1.246412e+07 -6.723963e+06 1.363236e+07 3.567856e+07 -4.168974e+05 ... 3.582187e+07 6.317101e+07 7.657796e+07 2.278843e+07 4.932417e+07 6.821452e+07 8.194208e+07 2.309931e+07 6.415660e+07 7.939068e+07
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1256 600898.XSHG 8.464410e+06 5.893172e+06 4.892272e+06 4.455146e+06 -5.360487e+04 4.851442e+05 4.233041e+06 -2.189779e+06 -4.072263e+06 ... 5.479146e+06 1.541125e+06 6.989806e+06 7.430564e+05 -1.489971e+07 -6.777860e+06 3.338122e+07 5.217981e+06 -5.009576e+07 -5.766829e+07
1257 600900.XSHG 3.425889e+08 1.071741e+09 1.160486e+09 7.638550e+08 4.009838e+08 9.112783e+08 1.149300e+09 1.153673e+09 3.957353e+08 ... 5.792040e+09 8.657862e+09 4.442578e+09 2.708003e+09 5.396815e+09 9.650829e+09 4.505264e+09 2.832197e+09 5.690227e+09 9.400000e+09
1258 600960.XSHG 1.042234e+07 4.118250e+06 -5.538210e+06 -1.234143e+05 4.502931e+06 4.439451e+06 2.739069e+05 5.101862e+06 6.223159e+06 ... 1.710609e+07 4.808618e+06 8.045850e+07 6.277999e+07 5.756132e+07 4.258602e+07 7.540715e+07 3.428047e+07 4.284034e+07 -8.707265e+06
1259 600961.XSHG 1.639785e+07 2.283805e+07 2.355567e+07 1.090249e+07 8.178774e+07 1.281012e+08 9.156157e+07 1.168537e+08 1.022791e+08 ... 6.390952e+06 1.987720e+07 -1.093709e+07 2.790871e+06 4.073789e+06 3.619205e+07 1.239287e+07 -3.212782e+07 -1.327732e+09 -2.114965e+08
1260 600962.XSHG 4.001726e+06 1.628266e+07 7.582702e+06 6.257167e+06 5.695868e+06 2.072742e+07 7.040132e+06 5.814756e+06 6.452912e+06 ... 4.211484e+06 -6.139921e+06 -2.617137e+06 2.232641e+06 -6.148102e+05 -1.354590e+06 8.052612e+06 2.261782e+06 4.392392e+06 -7.998890e+04
1261 600963.XSHG 1.650274e+07 2.385905e+07 1.876115e+07 3.534841e+07 9.527372e+06 1.344888e+07 2.156778e+07 3.485191e+07 1.041410e+07 ... 8.862017e+06 4.900530e+06 9.692581e+06 1.476743e+07 6.658310e+07 1.184473e+08 1.479404e+08 1.533521e+08 1.421723e+08 4.550432e+07
1262 600965.XSHG 6.944028e+06 -2.054114e+06 5.094084e+06 1.704425e+05 3.817957e+06 3.884872e+06 4.772755e+06 5.401562e+06 2.347712e+06 ... 4.417163e+07 6.239547e+07 3.740856e+07 2.477040e+07 4.075511e+07 5.382735e+07 3.720519e+07 3.627967e+07 4.915033e+07 5.906586e+07
1263 600966.XSHG 2.393009e+07 2.515846e+07 3.551350e+07 4.262032e+07 3.354268e+07 4.002889e+07 3.831753e+07 3.499718e+07 3.023965e+07 ... 5.515784e+07 4.141855e+07 9.418862e+07 1.971598e+08 2.082087e+08 2.048487e+08 2.459188e+08 2.050617e+08 2.064003e+08 9.798230e+07
1264 600967.XSHG -1.050549e+07 1.882040e+07 -1.756489e+07 -1.226036e+06 4.675392e+06 4.309188e+06 1.818385e+06 -6.234042e+05 3.021271e+06 ... 8.721762e+06 5.972160e+06 5.289293e+08 6.956315e+07 1.266016e+08 1.241176e+08 2.047392e+08 6.036549e+07 2.285406e+08 6.039895e+07
1265 600969.XSHG 9.439904e+06 1.786097e+07 1.730774e+07 -1.344586e+06 8.188338e+06 1.833965e+07 -8.080932e+06 -7.569316e+07 1.153530e+07 ... 4.395522e+07 2.781264e+07 1.424502e+07 1.495702e+07 3.457970e+07 2.268553e+07 -4.202632e+07 1.746685e+07 2.746331e+07 1.302200e+07
1266 600971.XSHG 4.762456e+07 5.948809e+07 3.961183e+07 5.581461e+07 3.648625e+07 7.252908e+07 5.849507e+07 3.592880e+07 4.389130e+07 ... 5.199185e+07 6.018165e+07 -8.168775e+07 2.876308e+08 3.437379e+08 3.203954e+08 1.529850e+08 2.039585e+08 2.487031e+08 2.360981e+08
1267 600973.XSHG 6.436672e+06 1.614351e+07 1.103578e+07 1.491643e+07 7.181190e+06 2.505792e+07 3.925734e+07 3.955455e+07 2.380238e+07 ... 5.149868e+07 8.818911e+07 8.750302e+07 3.023454e+07 3.840370e+07 3.178715e+07 -1.418800e+07 3.289337e+07 4.882339e+07 3.303417e+07
1268 600975.XSHG 3.287704e+06 1.369457e+07 5.964054e+06 4.110096e+06 6.503236e+06 1.201192e+07 5.873118e+06 1.531092e+06 2.178982e+06 ... 8.875455e+07 6.295189e+07 -8.969935e+06 3.338492e+07 7.748292e+06 1.146655e+07 -7.687780e+06 -4.739962e+06 -5.135375e+07 1.263998e+07
1269 600976.XSHG 3.873238e+06 2.314069e+06 9.519194e+06 4.384467e+06 3.888787e+06 2.338454e+06 9.066325e+06 -4.317406e+06 2.040220e+06 ... 1.891036e+07 1.425287e+07 8.416051e+06 1.770096e+07 3.046029e+07 2.435138e+07 1.826492e+07 2.892277e+07 2.856973e+07 1.537626e+07
1270 600978.XSHG 1.462866e+07 2.673167e+07 2.468108e+07 3.825690e+07 1.994878e+07 4.052494e+07 4.937042e+07 6.279824e+07 3.581164e+07 ... 2.570031e+08 2.208997e+08 9.939734e+07 1.603021e+08 3.093541e+08 2.332745e+08 4.984250e+07 1.845731e+08 1.933229e+08 1.512296e+08
1271 600979.XSHG 7.325732e+06 1.014156e+07 8.263076e+06 4.677814e+06 8.374360e+06 1.176300e+07 4.353368e+06 5.044768e+06 -1.874043e+06 ... 1.026783e+08 4.491207e+07 4.505411e+07 4.657706e+07 1.037381e+08 5.519330e+07 7.247247e+07 4.563816e+07 7.634370e+07 8.080097e+07
1272 600980.XSHG 2.295718e+06 6.857227e+06 5.581048e+06 2.300065e+06 1.978940e+06 4.729794e+06 2.851372e+06 -9.120374e+04 -5.670275e+06 ... 6.705288e+06 5.660532e+06 1.886416e+07 4.027821e+06 1.143389e+07 1.544739e+07 1.240928e+07 3.856235e+06 1.447235e+07 1.247279e+07
1273 600981.XSHG 1.065796e+07 1.148088e+07 7.068396e+06 1.137183e+07 1.155087e+07 1.644092e+07 1.243265e+07 2.681934e+07 1.201355e+07 ... 2.711596e+08 2.092268e+08 1.020502e+08 1.537087e+08 8.880521e+07 1.077641e+08 3.865157e+08 1.191863e+08 1.131776e+08 7.471018e+08
1274 600982.XSHG 4.281654e+06 6.705802e+06 4.566356e+06 6.949520e+06 5.604586e+06 8.045174e+06 7.814602e+06 5.117616e+06 6.546200e+06 ... 2.511687e+07 1.386466e+07 3.224891e+07 3.615686e+07 2.713796e+07 2.945559e+07 3.239511e+06 1.943982e+07 7.140294e+07 3.840016e+07
1275 600983.XSHG 1.345063e+07 7.399818e+06 5.560460e+06 1.269905e+07 2.032765e+07 1.013237e+07 6.975385e+06 1.415601e+07 2.280917e+07 ... 5.054458e+07 6.902410e+07 1.229382e+08 1.160906e+08 -2.019653e+08 2.926529e+07 -4.036627e+07 5.761938e+07 2.315115e+08 6.518851e+07
1276 600984.XSHG -1.659172e+07 1.441104e+05 -3.115245e+06 -3.008556e+07 -2.029600e+07 -5.830537e+06 -8.680984e+06 -2.451750e+07 -3.877424e+06 ... 5.368713e+07 3.920386e+07 1.171819e+07 -1.017455e+07 6.670756e+07 3.264023e+07 -6.636414e+07 -6.146208e+06 6.539040e+07 5.724389e+07
1277 600985.XSHG 9.189136e+05 3.735309e+06 2.504943e+06 1.875645e+06 2.508210e+06 4.860658e+06 4.435712e+06 2.666590e+06 3.274815e+06 ... 4.076968e+07 3.156383e+07 3.020835e+06 1.348480e+07 3.770077e+07 2.701728e+07 4.068956e+07 1.321977e+07 5.894860e+07 8.233867e+08
1278 600986.XSHG 5.680646e+06 7.825827e+06 1.116868e+07 -8.991066e+06 -1.851295e+06 1.026871e+07 4.412814e+06 1.273366e+07 3.024452e+05 ... 1.402019e+08 1.506912e+08 1.132081e+08 9.702917e+07 1.071296e+08 1.162372e+08 1.423145e+08 8.752948e+07 2.960949e+08 6.447398e+07
1279 600987.XSHG 5.717522e+06 9.561671e+06 1.039783e+07 7.236466e+06 8.500018e+06 2.306312e+07 1.780593e+07 1.758933e+07 2.462099e+07 ... 1.447736e+08 1.204827e+08 1.856930e+08 9.360674e+07 1.496637e+08 1.331838e+08 1.971025e+08 1.034424e+08 1.743545e+08 1.423594e+08
1280 600988.XSHG -2.835117e+06 -1.002159e+07 -1.855482e+07 -1.595520e+08 -7.449058e+06 -8.802350e+06 -7.870430e+06 -1.966989e+08 -4.591284e+06 ... 7.314901e+07 6.338102e+07 1.688377e+08 7.691240e+06 7.196733e+07 7.315293e+07 1.215452e+08 3.111367e+07 3.114142e+07 2.245070e+07
1281 600990.XSHG -1.956695e+06 8.311380e+06 4.306474e+06 7.636620e+06 6.596490e+05 8.165685e+06 1.760184e+06 9.166936e+06 7.449538e+05 ... 7.517914e+06 2.157753e+07 9.949399e+07 7.986148e+05 -4.402583e+07 1.139130e+08 1.306173e+08 -5.892835e+07 2.189658e+07 3.231392e+07
1282 600992.XSHG 1.031072e+07 1.210298e+07 1.115426e+07 9.673980e+06 1.051803e+07 1.246492e+07 1.069471e+07 1.171033e+07 9.790027e+06 ... 4.507365e+06 4.739330e+06 7.888510e+06 5.074704e+06 4.494648e+06 4.206957e+06 8.408575e+06 5.236255e+06 6.410481e+06 5.387073e+06
1283 600993.XSHG 1.471240e+07 1.960376e+07 1.009279e+07 1.565120e+07 1.453188e+07 2.489963e+07 1.505335e+07 1.711289e+07 4.588869e+07 ... 7.800795e+07 4.858552e+07 4.339742e+07 8.669642e+07 8.764631e+07 6.133823e+07 8.437046e+07 6.831314e+07 3.432039e+07 1.805244e+07
1284 600995.XSHG 9.014610e+06 1.385436e+07 3.465900e+07 1.960377e+07 8.946382e+06 1.097101e+07 3.273336e+07 2.403476e+07 8.071080e+06 ... 3.390543e+07 2.849368e+07 1.187990e+07 9.480771e+07 1.044731e+08 2.310196e+07 -6.568646e+07 1.872558e+08 9.587799e+07 4.542449e+07
1285 600997.XSHG 9.395502e+07 8.911074e+07 1.145479e+08 1.011593e+08 1.004171e+08 1.178371e+08 1.006854e+08 1.692842e+08 1.055415e+08 ... 3.842778e+07 1.497362e+08 2.278754e+08 1.478670e+08 7.876888e+07 1.007744e+08 1.891135e+08 2.545456e+08 3.277310e+08 4.088321e+08

1286 rows × 56 columns

#对单季度净利润进行处理,得到所有季度的净利润
all_investment=pd.DataFrame()
all_investment['code']=all_single_investment['code']
for i in season_all:
    if i in q1:
        all_investment[i]=all_single_investment[i]
    elif i in q2:
        all_investment[i]=all_single_investment[i]+all_single_investment[season_all[(season_all.index(i)-1)]]
    elif i in q3:
        all_investment[i]=all_single_investment[i]+all_single_investment[season_all[(season_all.index(i)-1)]]+all_single_investment[season_all[(season_all.index(i)-2)]]
    else:
        all_investment[i]=all_single_investment[i]+all_single_investment[season_all[(season_all.index(i)-1)]]+all_single_investment[season_all[(season_all.index(i)-2)]]+all_single_investment[season_all[(season_all.index(i)-3)]]
all_investment.head()
code 2005q1 2005q2 2005q3 2005q4 2006q1 2006q2 2006q3 2006q4 2007q1 ... 2016q2 2016q3 2016q4 2017q1 2017q2 2017q3 2017q4 2018q1 2018q2 2018q3
0 000001.XSHE 1.541264e+08 1.578348e+08 3.167711e+08 2.613557e+08 2.331836e+08 4.636207e+08 8.902956e+08 1.302907e+09 5.350836e+08 ... 1.229200e+10 1.871900e+10 2.259900e+10 6.214000e+09 1.255400e+10 1.915300e+10 2.318900e+10 6.595000e+09 1.337200e+10 2.045600e+10
1 000002.XSHE 2.519146e+08 7.950525e+08 8.717931e+08 1.350363e+09 4.102369e+08 1.270579e+09 1.453370e+09 2.297884e+09 6.123493e+08 ... 5.351310e+09 8.262381e+09 2.102261e+10 6.954116e+08 7.302724e+09 1.109100e+10 2.805181e+10 8.948780e+08 9.123743e+09 1.398456e+10
2 000004.XSHE -1.313875e+06 -2.278127e+06 -5.066621e+06 -1.357701e+07 1.726932e+05 -1.693866e+06 -4.168663e+06 6.988959e+05 1.036046e+05 ... 2.985718e+06 1.469853e+07 3.929931e+07 -1.177969e+06 -3.772074e+06 -5.434258e+06 8.566721e+06 2.060513e+06 1.983825e+06 -2.591750e+06
3 000005.XSHE -6.646618e+06 -1.487059e+07 -2.480444e+07 -1.799700e+08 5.914588e+07 6.810817e+07 7.309013e+07 -6.495440e+07 3.984999e+07 ... 1.269780e+08 1.337694e+08 1.086573e+08 -1.014027e+07 -1.775729e+07 -1.621331e+07 1.530844e+07 1.614733e+07 8.146692e+06 6.531952e+06
4 000006.XSHE 1.584547e+07 1.448365e+06 2.396126e+07 1.111913e+08 3.512168e+07 1.706320e+08 1.785897e+08 2.162561e+08 1.365658e+07 ... 1.020852e+08 1.144829e+08 7.785809e+08 1.038588e+08 2.496065e+08 3.391368e+08 8.056364e+08 2.862077e+08 4.159687e+08 5.032401e+08

5 rows × 56 columns

 

全部回复

0/140

量化课程

    移动端课程