python - 从熊猫数据框中的 ufloat 中提取名义偏差和标准偏差
问题描述
为方便起见,我使用 pandas 数据帧来对大量数据执行不确定性传播。
然后我希望绘制我的数据集的标称值,但类似的东西myDF['colLabel'].n
不起作用。如何从数据框中提取名义偏差和标准偏差以绘制名义值和误差线?
这是一个更一致的 MWE:
#%% MWE
import pandas as pd
from uncertainties import ufloat
import matplotlib.pyplot as plt
# building of a dataframe filled with ufloats
d = {'value1': [ufloat(1,.1),ufloat(3,.2),ufloat(5,.6),ufloat(8,.2)], 'value2': [ufloat(10,5),ufloat(50,2),ufloat(30,3),ufloat(5,1)]}
df = pd.DataFrame(data = d)
# plot of value2 vs. value1 with errobars.
plt.plot(x = df['value1'].n, y = df['value2'].n)
plt.errorbar(x = df['value1'].n, y = df['value2'].n, xerr = df['value1'].s, yerr = df['value2'].s)
# obviously .n and .s won't work.
我得到一个错误AttributeError: 'Series' object has no attribute 'n'
,建议从每个系列中提取值,有没有比通过循环将标称值和标准值分成两个单独的向量更短的方法?
谢谢。
编辑:使用包中的这些功能也不起作用:uncertainties.nominal_value(df['value2'])
和uncertainties.std_dev(df['value2'])
解决方案
实际上用不确定性的
unumpy.nominal_values(arr)
和unumpy.std_devs(arr)
函数解决了它。
推荐阅读
- php - WooCommerce - 如果金额大于 x,则将每个运费设置为 0(我有 90% 的工作片段但无法修改)
- javascript - 有没有办法一次捕获多个相同类型的事件?
- ruby-on-rails - 与名称中最后一个字母 s 的 Leagcy 表连接
- c++ - 如何在遍历时添加要设置的元素?
- json - JSON.parse 从 Web api 返回 undefined
- xamarin - Xamarin 使用 Skia Sharp 形成 Dotted Circle
- javascript - 谷歌分析没有收集任何网站速度数据
- cplex - 使用 cplex OPL 对时空网络进行建模
- git - 除了最后一次提交删除之前的所有提交
- c# - 使用 Excel 互操作时忽略 Excel 中设置的日期格式