python - dataframe issue to shift a function

Viewed 34

I have some difficulties.

I would like to create 2 functions : P1, P2 P1 and P2 are the same except that P2 is shifted by one on the x

but here my problem : I would like to addition P1 + P2 and when I do that my data frame is like that :

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
...

except that I expect a dataframe like that

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
...

here my code, where is the issue please ?

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
0 Answers
Related