我的pandas数据框有数千列,我想计算新列' future_calcs',它将包含字符串 - 列的名称,这些列按其值排序并用逗号分隔。此列的内容将用于其他计算。 由于大量的列我想在熊猫级别上进行所有计算。
df = pd.DataFrame(np.random.randint(100, size=(4,3)), columns['aaa','bbb','ccc'])
aaa bbb ccc
0 70 27 32
1 15 27 4
2 51 17 37
3 95 27 88
我想要
aaa bbb ccc future_calcs
0 70 27 32 aaa,ccc,bbb <--- aaa > ccc > bbb
1 15 27 4 bbb,aaa,ccc
2 51 17 37 aaa,ccc,bbb
3 95 27 88 aaa,ccc,bbb
答案 0 :(得分:1)
您可以使用numpy.argsort
作为列名:
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var foodtr = require('./../model/foodtruck');
var foodtrucklist = function(req, res) {
foodtr.find().populate('item_list').exec(function(err, foodtrucks) {
foodtrucks.forEach(function(ftr) {
var start_time = ftr.foodtruck_starting_timing;
var end_time = ftr.foodtruck_closing_timing;
var foodtruck_open_status = ftr.foodtruck_open_status;
// var shut_down = ftr.foodtruck_shutdown;
if ((start_time && end_time) &&
(start_time.trim() != '' &&
end_time.trim() != '')) {
if (inTime(start_time, end_time) &&
foodtruck_open_status ==0 ) {
ftr.foodtruck_open_status = 0;
ftr.save();
} else {
ftr.foodtruck_open_status = 1;
ftr.save();
}
}
})
res.json({
status: '200',
message: 'foodtrucklist',
data: foodtrucks
});
});
};