在某一列上进行过滤,而在另一列上进行排名,而无需在数据框中分组

时间:2018-08-11 07:32:24

标签: python python-3.x pandas dataframe

我有一个数据框,其中包含4列Student_name,total_marks,is_shortlisted,rank

我想根据is_shortlisted =“ Y”的total_marks列对行进行排名。

样本输入数据:

name     total_marks   is_shortlisted
Aman       67              Y
Nitin      89              Y
Ankur      76              Y
Mohit      56              N
Ashish     64              Y

样本输出数据:

name     total_marks   is_shortlisted  rank 
Aman       67              Y            3
Nitin      89              Y            1
Ankur      76              Y            2
Mohit      56              N            nan
Ashish     64              Y            4

1 个答案:

答案 0 :(得分:3)

const mongoose = require("mongoose"); var CarSchema = new mongoose.Schema({ showroom: { type: String, required: true, index: true }, doors: { type: String, required: true }}); var paginate = require('mongoose-paginate'); CarSchema.plugin(paginate); CarSchema.statics = { list({ page = 1, perPage = 30, name, email, role }) { const options = omitBy({ name, email, role }, isNil); // this.paginate is undefined here return this.paginate(options) .sort({ createdAt: -1 }) .skip(perPage * (page - 1)) .limit(perPage) .exec(); } loc一起使用:

rank