使 plt.plot 遍历原点的代码

发布于 2025-01-09 02:20:16 字数 299 浏览 2 评论 0原文

我有一个名为 df 的 Pandas 数据框,只有 2 列数字:x 和 y。 为了使最适合的行穿过原点,我编写了这行代码:

x=df.iloc[1:28,0]
lst_sq_x=df.iloc[1:28,0].values.reshape(-1,1)
lst_sq_y=df.iloc[1:28,1] 

plt.plot(x, np.linalg.lstsq(lst_sq_x, lst_sq_y)[0][0])(x))

但是,这行代码不起作用(语法无效)。你能告诉我我做错了什么吗?

I have a Pandas data frame called df with only 2 columns of numbers: x and y.
To make the line of best fit go through the origin, I have made this line of code:

x=df.iloc[1:28,0]
lst_sq_x=df.iloc[1:28,0].values.reshape(-1,1)
lst_sq_y=df.iloc[1:28,1] 

plt.plot(x, np.linalg.lstsq(lst_sq_x, lst_sq_y)[0][0])(x))

However, this line does not work (invalid syntax). Will you tell me what I'm getting wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文