原帖由
horizon2 于 2019-3-11 11:03:27 發(fā)表
請(qǐng)問(wèn)這個(gè)軟件是您編寫的嗎?我也在學(xué)python,想向您學(xué)習(xí)一下方法和方向,請(qǐng)幫忙加一下微信號(hào),謝謝!我的微信號(hào)是:horizon2
用pandas貌似也簡(jiǎn)單
data結(jié)構(gòu)如下:
date_id cell a b c
0 2019-01-01 cella 39 17 786
1 2019-01-02 cella 66 569 882
2 2019-01-03 cella 16 850 960
3 2019-01-01 cellb 40 427 742
4 2019-01-02 cellb 9 578 78
5 2019-01-03 cellb 14 620 831
6 2019-01-01 cellc 67 333 831
7 2019-01-02 cellc 68 289 92
8 2019-01-03 cellc 59 508 264
取每個(gè)cell的a列top2時(shí)對(duì)應(yīng)行的數(shù)據(jù):
df = pd.read_csv('data.csv')
df['num'] = df['a'].groupby(df['cell']).rank(ascending=0,method='first')
df[df.num <=2]