我有一个数据框,其中包含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
答案 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