我想使用pandas lambda表达式实现以下目标
答案 0 :(得分:1)
您会喜欢以下内容吗?
编写一个函数以减去两个素数列中的值:
var quart = [
["48.85585695936588,2.317734961729684"],
["48.87234429654349,2.351466422300973"],
["48.85376742273335,2.3639977028185513"]
];
var points = [];
quart.forEach(function(item) {
var coords = item[0].split(',');
points.push({
lat: parseFloat(coords[0]), // added float parsing in Edit
lng: parseFloat(coords[1])
});
})
console.log(points);
应用功能,将其分配给新列:
def get_col_name(x):
try:
ip_fc = x['ideal_prime_fc']
p_fc = x['prime_fc']
return x[ip_fc]-x[p_fc]
except IndexError:
return float('NaN') # handle non-existent values however you'd prefer
截断的示例输出:
df['diff'] = df.apply(lambda x: get_col_name(x), axis=1)