首页 > 解决方案 > 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

标签: pythondataframe

解决方案


推荐阅读