python pandas groupby 之后 根据多列求unique

嗯heng
  • 21

R语言转成python. 求助
SingleVRef
image.png
R 语言如下

SingleVRef<- unique(SingleVRef[,c("Parameter","Step","max","min")])

写成下面的感觉不对劲

        SingleVRef['max'] = SingleVRef.groupby(['Par','Step'])['Value'].transform(lambda x: x.max())
        SingleVRef['min'] = SingleVRef.groupby(['Par','Step'])['Value'].transform(lambda x: x.min())# min=min(Value))
        SingleVRef = SingleVRef[["Par","Step","max","min"]].groupby(['Par','Step']).apply(lambda x: list(np.unique(x)))
SingleVRef.columns=["Par","Step","refUL","refLL"] 

image.png

回复
阅读 351
1 个回答
✓ 已被采纳
宣传栏