あなただけsort_valuesを使用することができます。
final.assign(sortkey = df.test.apply(list).str[0])\
.sort_values(by=['sortkey','count'], ascending=[True, False])\
.drop('sortkey', axis=1)
例:
df = pd.DataFrame({'test':np.random.choice([{'Test1'},{'Test2'},{'Test3'}], 30),'count':np.random.randint(1000,5000, 30)})
df_out = df.assign(sortkey = df.test.apply(list).str[0])\
.sort_values(by=['sortkey','count'], ascending=[True, False])\
.drop('sortkey', axis=1)
df_out
出力:
count test
13 4121 {Test1}
23 2859 {Test1}
26 2125 {Test1}
0 1569 {Test1}
5 4620 {Test2}
27 4575 {Test2}
25 4336 {Test2}
22 3870 {Test2}
9 2460 {Test2}
17 2083 {Test2}
11 1689 {Test2}
24 1549 {Test2}
2 1093 {Test2}
4 4711 {Test3}
10 4536 {Test3}
12 4359 {Test3}
8 4288 {Test3}
18 4167 {Test3}
20 4085 {Test3}
15 3841 {Test3}
3 3379 {Test3}
7 3108 {Test3}
28 3027 {Test3}
21 2927 {Test3}
14 2491 {Test3}
1 2128 {Test3}
16 2114 {Test3}
19 2045 {Test3}
6 1927 {Test3}
29 1410 {Test3}
@Armanはいその起因の画像を埋め込むことができない@Arman –
を更新しました評判のポイントがない。 (最低10) –
@RohiniReddyCJはあなたのコードをテキストとして表示します。 – eyllanesc