pandas - 无法强制列表到系列/数据框
问题描述
我正在尝试使用带有以下代码的 lmfit 来拟合 x 和 y 数据
mod = ExpressionModel(
self._expr,
independent_vars=[x],
)
# pars = mod.guess(raw_y, x=raw_x)
if guess:
pars = mod.make_params(**guess)
else:
# TODO custom error needs to be implemented
print("No guess was passed")
raise Exception
# thinnen the fit data to avoid over fitting
# x_fit = np.array_split(x_data.iloc[::2], 2)[0]
# y_fit = np.array_split(y_data.iloc[::2], 2)[0]
print(x_data)
x_fit = np.array(x_data.to_numpy(copy=True)).transpose()
y_fit = y_data
print(x_fit.shape)
print(x_fit.T)
print(y_fit)
stuff = {x_data.name:x_fit}
# stuff = {x_data.name:x_data}
out = mod.fit(y_fit, pars,**stuff)
以下是我拥有的数据的打印:
0 3.0
1 1.5
2 1.0
Name: r, dtype: float64
(3,)
[3. 1.5 1. ]
na
0 0.050000
1 0.025000
2 0.016667
我收到以下错误:
文件“/home/bob/Programming/Lab-Tool/env/lib/python3.8/site-packages/pandas/core/frame.py”,第 6864 行,在 _arith_method self, other = ops.align_method_FRAME(self, other , 轴, flex=True, level=None) 文件“/home/bob/Programming/Lab-Tool/env/lib/python3.8/site-packages/pandas/core/ops/init .py ”,第 277 行,在 align_method_FRA ME 中引发 ValueError(ValueError: Unable to coerce list of <class 'pandas.core.series.Series'> to Series/DataFrame
或者如果我使用 x_fit:
raise ValueError(ValueError: Unable to force to list of <class 'numpy.ndarray'> to Series/DataFrame
有人知道我的错误吗?
解决方案
推荐阅读
- python - 在 jupyter 中带有 Folium 的 Python 映射错误
- flutter - 如何使用图标宽度颜色制作图标
- firebase - 同一 Flutter 项目中的 Firebase ML-vision 和 admob 插件问题 - 播放服务版本冲突
- microsoft-graph-api - 如何从使用图形客户端发送的消息中获取信息
- angular - 重用reducers逻辑
- javascript - Javascript ES6 书单错误
- youtube-api - YouTube 数据 API“youtube#channel”查询:“brandingSettings.image”自 2020 年 11 月 11 日起不再可用?
- c# - 如何在 sonarcloud.io 中为 c# 项目启用代码覆盖率
- python - 使用具有许多不同键的 R 巨大 json 进行解析
- virtualization - libvirt:virt-install 在安装时挂起