处理pandas数据框架和系列中的不确定性
upandas的Python项目详细描述
upandas
upandas使得在pandas数据帧和序列中使用具有不确定性的数量变得容易。
upandas依赖于优秀的uncertainties包,当然还有pandas。
# A dataframe with nominal values in columns x and y,# and their respective uncertainties in u_x, u_yIn[1]:n=3;df=pd.DataFrame({'x':randn(n),'u_x':0.1*rand(n),...:'y':randn(n),'u_y':0.1*rand(n)})In[2]:dfOut[2]:xu_xyu_y0-1.7352880.014020-1.4264110.0938791-0.6777560.084329-1.2542120.03460122.4101810.054435-1.6113070.020315# Convert col/u_col pairs to uarray columnsIn[3]:uf=separate_to_u(df)In[4]:ufOut[4]:xy0-1.735+/-0.014-1.43+/-0.091-0.68+/-0.08-1.254+/-0.03522.41+/-0.05-1.611+/-0.020# Operate on columns in the DataFrame as usual,# but propagate the uncertaintiesIn[5]:uf['xy2']=uf['x']*uf['y']**2In[6]:ufOut[6]:xyxy20-1.735+/-0.014-1.43+/-0.09-3.5+/-0.51-0.68+/-0.08-1.254+/-0.035-1.07+/-0.1522.41+/-0.05-1.611+/-0.0206.26+/-0.21# Convert back to a conventional dataframe# for e.g. storage to HDF5.In[17]:u_to_separate(uf)Out[17]:xu_xyu_yxy2u_xy20-1.7352880.014020-1.4264110.093879-3.5306980.4656201-0.6777560.084329-1.2542120.034601-1.0661430.14511222.4101810.054435-1.6113070.0203156.2575760.211830
开始
先决条件
upandas依赖于不确定性和熊猫, 但如果需要,pip会安装这些。
安装
pip install upandas
运行测试
包括基本测试,使用pytest。在基本目录中:
pytest tests
或者只是make test
。
用法
到目前为止,upandas仅提供两个功能:
separate_to_u(df)
:将列、u列对转换为uarray列列。u_to_separate(df)
:将uarray列列转换为成对列,u列。
如果应用于序列,这些函数将查看“行”索引,而不是列。
使用
构建注意,作为一个“现代”python项目,它使用pyproject.toml而不是setuptoolssetup.py
。
如果要在本地开发,请拉取此存储库并执行…待定。
贡献
请给我发送请求!
版本控制
我们使用SemVer进行版本控制。
作者
- lincoln turner-lincolndturner
待办事项
- 多索引支持。
- 把ufloats做成熊猫,尽管不清楚这是必要的。
- 将uarray设为pandas[https://pandas.pydata.org/pandas docs/stable/reference/api/pandas.api.extensions.extensionArray.html pandas.api.extensions.extensionArray]扩展数组,但仍然不清楚是否需要。
- 注册pandascustom accessors,这样我们就可以在转换上更像Python了:
df.u.from_separate()...
, - 。以及
df.u.nomnal_values
,df.u.std_devs
。 - 更多测试
许可证
此项目在monash/bsd 2子句许可下获得许可-有关详细信息,请参见LICENSE文件。
致谢
受到不确定性广泛支持的启发 在lyse中, 作为labscript suite的一部分。