python - Concat, Groupby and sum() panda -
python - Concat, Groupby and sum() panda -
i have timestamped ohlc info trying recreate uncompressed high-low dataframe iterating through original ohlc dataframe.
ohlc dateframe looks this:
open high low close index1 r1 tpo timestamp 2014-05-07 09:30:00 187.40 187.62 187.16 187.16 0 0.46 na 2014-05-07 10:00:00 186.96 187.32 186.13 186.18 1 1.19 na 2014-05-07 10:30:00 186.47 186.90 186.47 186.88 2 0.43 na 2014-05-07 11:00:00 186.78 186.97 186.67 186.68 3 0.30 na 2014-05-07 11:30:00 186.85 187.69 186.85 187.69 4 0.84 na
the thought here recreate each bar in row , create dataframe of filled range. each row phone call function recreate filled range row i. works fine , creates , returns row dataframe in x1 or x2.
next, want append, concatenate dataframe the 1 prior in cumulative concat function..it appears correctly
def tpoprint(low,high,tick): range=np.arange(low,high,tick) p1=pd.dataframe({'price':range,'count':np.ones(len(range),dtype=np.int)},index=range) homecoming p1 i, row in bars.iterrows(): if counter>0: low=bars.low[i] high=bars.high[i] x2=tpoprint(low,high,tick_size) if x2.empty: print('dataframe empty! skipped ', bars.index1[i]) tpotemp=pd.concat([x1,x2]) x1=tpotemp tpo=x1.groupby(x1.index) g=tpo.sum()
lastly, after concatenations completed, want grouping cost , sum of count @ each price... problem occurs. though perform grouping by, duplicate prices not combining , hence summing not happening. can see output below not correct. stuck , don't understand why.
i want perform histograms on data, if know why happening appreciate it.
count cost 186.46 1 186.46 186.47 1 186.47 186.47 1 186.47 186.48 1 186.48 186.48 1 186.48 186.49 1 186.49 186.49 1 186.49 186.50 1 186.50 186.50 1 186.50 186.51 1 186.51 186.51 1 186.51 186.52 1 186.52 186.52 1 186.52 186.53 1 186.53 186.53 1 186.53 186.54 1 186.54 186.54 1 186.54 186.55 1 186.55 186.55 1 186.55 186.56 1 186.56 186.56 1 186.56 186.56 1 186.56 186.57 1 186.57 186.57 1 186.57
python numpy pandas
Comments
Post a Comment