我正在获取特定列的行数,如下所示:
subreddit_count = df['body'].groupby(df['subreddit']).agg(['count'])
返回以下df:
subreddit count
0 0xProject 12
1 100sexiest 1
2 100yearsago 2
3 1022 3
4 1200isjerky 2
5 1200isplenty 37
6 1200isplentyketo 1
7 12ozmouse 1
8 12thMan 4
9 12winArenaLog 1
10 13ReasonsWhy 5
11 13or30 3
12 14ers 1
13 1500isplenty 1
14 15SecondStories 3
15 18650masterrace 1
16 18_19 10
17 1911 5
18 195 2
19 19KidsandCounting 4
20 1P_LSD 18
21 2007oneclan 2
22 2007scape 1044
23 2010sMusic 1
24 21savage 1
25 22lr 1
26 23andme 9
27 240sx 4
28 24CarrotCraft 1
29 24hoursupport 5
我想基本上撤消groupby,以便将这些计数添加到原始df中的每一行。我尝试过使用reset_index无济于事。什么是正确的方法?