社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Sacha Bernheim

Sacha Bernheim 最近创建的主题
Sacha Bernheim 最近回复了

你可以试试这样的方法:

# sort dataframe
df.sort_values(by=['count'], inplace=True)
# recreate the index of your rows to make sure that 0 corresponds to the one with the higher count
df.reset_index(drop=True, inplace=True)
# add your new row to your dataset
df.append({'useragent': 'Others', 'count': df.loc[5:]['count'].cumsum()}, inplace=True)
# drop the rows you don't need anymore
df.drop([5:len(df.index.values.tolist())-1], inplace=True)

我不完全确定,但值得一试。我希望它能给你一些建议。