I have a pandas dataframe like this:
character count
0 a 104
1 b 30
2 c 210
3 d 40
4 e 189
5 f 20
6 g 10
我希望在数据框中仅保留前三个字符,其余字符则合并为others
,因此表格变成:
character count
0 c 210
1 e 189
2 a 104
3 others 100
我该如何实现这个目标?
谢谢。
new.reset_index(inplace=True, drop=True)
即可获得精确匹配 :) - zipa