python - python - 转移函数的数据框问题
问题描述
我有一些困难。
我想创建 2 个函数:P1、P2 P1 和 P2 是相同的,只是 P2 在 x 上移动了一个
但这是我的问题:我想添加 P1 + P2,当我这样做时,我的数据框是这样的:
index | 0 | 1 | 2 | 3
0 -1 | 2.71 | 2.71 | 5.42
1 -0.93 | 2.55 | 2.58 | 5.13
...
17 0.03 | 0.97 | 1.15 | 2.12
18 0.09 | 0.85 | 1.04 | 1.89
...
除了我期望这样的数据框
index | 0 | 1 | 2 | 3
0 | -1 | 2.71 | 0 | 2.71
1 | -0.93 | 2.55 | 0 | 2.55
...
17 | 0.03 | 0.97 | 2.71 | 3.68
18 | 0.09 | 0.85 | 2.58 | 3.43
...
这是我的代码,请问问题出在哪里?
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# variable
a= 1
alpha = 1
# abscisse des x
x = np.linspace(-1, 5, 100)
# abscisse des y
P1 = np.exp(-a*x1)
P2 = np.exp(-a*x2 + alpha)
R = P1 + P2
# creation du dataframe
df = pd.DataFrame()
df[0] = x
df[1] = P1
df[2] = P2
df[3] = R
解决方案
推荐阅读
- python - 如何将 python dict 转换为 csv 文件,其中键将是列?
- firebase - Firebase Auth:如何在创建用户后取消订阅 Auth 观察者然后再次订阅?
- python - 在 iterrows() 期间通过 Regex/startswith 选择列
- reactjs - 为什么我不能使用 Redux 更新状态?
- python - 如何在 Python 中描述蛋白质序列的疏水性?
- c# - Json序列化C#数据结构
- reactjs - 为什么 redux-thunk 在 Storybook 中不起作用?
- javascript - 在位于对象键中的数组内推送值时出现问题
- 2d - 出现错误 - ']' 标记之前的预期 ')'
- spring - 在 Spring MVC 中将列表从 application.yml 反序列化为 @Value