题解 | #某店铺消费最多的前三名用户#

某店铺消费最多的前三名用户

https://www.nowcoder.com/practice/c177c9ad7ffd4503826f29d07ca71924

# tip1:df.rank()函数的使用 https://zhuanlan.zhihu.com/p/87593543/
# tip2:df.sort_values()函数的使用 https://blog.csdn.net/qq_25443541/article/details/118697711

import pandas as pd 
df=pd.read_csv("./sales.csv")

# # 方法一:使用rank函数
# condit=df["monetary"].rank(axis=0,method="dense",ascending=False)<=3
# res=df[condit].reset_index(drop=True)
# # drop=False表示将原来的索引列还原为普通列;drop=False表示将原索引值丢弃。
# print(res)

# 方法二
res=df.sort_values(by="monetary",ascending=False,ignore_index=True).iloc[0:3,:]
# ignore_index表示新生成的数据中的索引是采用原数据的索引还是新生成的
print(res)

全部评论

相关推荐

牛客100866号技...:把电科加粗,把电科加粗,把电科加粗,两个吊车尾的项目合并成一个,再加一个管理系统。电科✌🏻在成都面中厂手拿把掐
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务