I print the report on terminal using below python code
print(kf.groupby(level='ErrorCode').apply(lambda x: x/x.sum()))
to get
ErrorCode ResponseType
0 CANCEL_ORDER_CONFIRM 0.7207
TRADE_CONFIRM 0.2792
1 CANCEL_ORDER_CONFIRM 0.7207
TRADE_CONFIRM 0.2792
dtype: float64
But the ErrorCode 0,1 have to be mapped to a different number. That mapping can be written in a file in any format. Currently I can write mapping file as
0 10.0.0.0
1 10.0.0.1
2 10.2.0.1
Format of above can be changed. Is there a way to replace grouped value output by mapped values. Final output would be like
ErrorCode ResponseType
0 10.0.0.0 CANCEL_ORDER_CONFIRM 0.7207
TRADE_CONFIRM 0.2792
1 10.0.0.1 CANCEL_ORDER_CONFIRM 0.7207
TRADE_CONFIRM 0.2792
dtype: float64
It is even ok, if this can be done in bash, but alignment should be readable.
If this is very tricky, then I would simply make ErrorCode column values to change according to mapping file (but I think that too is not a very good approach)
Update1: Similarly I have data.groupby([data['ErrorCode'], pd.Grouper(freq='1500T')])['latency'].describe().unstack(0)
and my output is
ErrorCode 0 1
Time_req
2017-03-08 count 111.000000 111.000000
mean 251509.738739 357710.729730
std 250469.755466 795885.356352
min 104877.000000 111343.000000
25% 132616.000000 131953.000000
50% 160899.000000 163100.000000
75% 261440.000000 279448.000000
max 2071299.000000 8039122.000000
But I need to map ErrorCode using a dictionary named myd
which is myd={0: '0 172.19.13.51', 1: '1 172.19.13.51'}
such that output is something like below
ErrorCode 0 172.19.13.51 1 172.19.13.51
Time_req
2017-03-08 count 111.000000 111.000000
mean 251509.738739 357710.729730
std 250469.755466 795885.356352
min 104877.000000 111343.000000
25% 132616.000000 131953.000000
50% 160899.000000 163100.000000
75% 261440.000000 279448.000000
max 2071299.000000 8039122.000000