使用几何标准偏差 (gstd) 进行聚合

问题描述

我想使用几何平均数和几何标准差(基于天分组)聚合数据框列表。数据帧具有日期时间索引,但有几天在所有数据帧中都不包含任何值。

数据:

                                 col1    col2        col3       col4    
datetime                        
2020-06-29 17:30:00+00:00   3.237216    2.919800    1.244800    0.247284    
2020-06-29 17:45:00+00:00   3.896863    3.522242    1.513753    0.324903    
2020-06-29 18:00:00+00:00   3.100665    2.796570    1.192138    0.273637
...     

我的代码

from scipy.stats.mstats import gmean
from scipy.stats import gstd

cols = ["col1","col2","col3","col4"]
joined = pd.concat(df.reset_index() for df in listdata)
#joined = joined.replace({np.nan:1,0:1})
joined[cols] = joined[cols].mask(joined[cols] < 0,1)

df = joined.set_index('datetime').groupby(pd.Grouper(freq='D'))

means = df.agg(gmean)
std = df.apply(gstd)
#std = df.agg(gstd)

gmean 运行良好,但 gstd 返回错误

ValueError: degrees of freedom <= 0 for slice  

有什么办法可以解决这个错误吗?是因为数据帧中错过了几天吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)