我正在使用一个看起来像下面的数据集(值已更改且实际值更大)
fruit_type, temp, count
apple, 12, 4
apple, 14, 6
pear, 12, 6
pear, 16, 2
grape 12, 5
peach, 9, 33
peach 6, 3
我正在尝试使用numpy agg函数来查找每个temp的每个计数的总计数百分比。我还希望用一列来表示总数。下面是我一直在尝试的代码。
data3 = data2.groupby('fruit_type')['count'].agg({
'prob' : lambda count: ((count) / count.sum()),
'total' : lambda count: count.size
})
临时值是离散的。我希望计算在一行一行的基础上汇总,其中总计数总和按水果类型分组。请告诉我我的代码有什么问题。
答案 0 :(得分:2)
问题是第一个import UIKit
var smoothLineView : SmoothLineView = SmoothLineView()
class ViewController: UIViewController {
@IBOutlet weak var mainDrawingCanvas: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
smoothLineView = SmoothLineView(frame: mainDrawingCanvas.bounds)
self.view.addSubview(smoothLineView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func deleteCurrentCanvas(sender: AnyObject) {
mainDrawingCanvas.image = nil
}
}
。它返回与组相同的形状,而不是将其聚合为标量。
您可能想要lambda count: count/count.sum()
代替transform
agg