小编f1r*_*cer的帖子

按时间和组别 Z-score

我有一个具有以下数据样式的数据框

我正在尝试按每个月为样式列中的每个公司计算 3 个因素(F1、F2、F3)的 z 分数(标准化) 比如说 2014 年 8 月 31 日,我想计算 z 分数(F1、F2 , F3 单独)在该风格(例如建筑材料)内为该月的该风格同行中的每个公司。同样在 2014 年 8 月 31 日,我想计算该月每个拥有“电子设备、仪器和组件”的公司的样式(例如电子设备、仪器和组件)的 z 分数。并且每个月重复这个过程。回顾一下,首先从日期开始,然后计算每种样式中的 z-score,然后每个月重复一次。

我尝试首先定义 z-score zscr=lambda x: (xx.mean())/x.std() 然后按日期、样式分组但没有得到想要的结果。

先感谢您

         Date  Name                                        Style   ID  \
0   8/31/2014   XYZ                          Construction Materials  ABC   
1   9/30/2014   XYZ                          Construction Materials  ABC   
2  10/31/2014   XYZ                          Construction Materials  ABC   
3  11/30/2014   XYZ                          Construction Materials  ABC   
4   8/31/2014  Acme  Electronic Equipment, Instruments & Components  KYZ   
5   9/30/2014  Acme  Electronic Equipment, Instruments & Components …
Run Code Online (Sandbox Code Playgroud)

python pandas scikit-learn pandas-groupby

1
推荐指数
1
解决办法
712
查看次数

标签 统计

pandas ×1

pandas-groupby ×1

python ×1

scikit-learn ×1