I have a dataframe like this:
Date,Close
1987-01-02,2540.100098
1987-01-05,2552.399902
1987-01-06,2583.899902
1987-01-07,2607.100098
1987-01-08,2603.300049
I'm trying to subtracting each row to all other rows but the result returns all NaN and I don't know why:
import pandas as pd
import numpy as np
df = pd.read_csv('test.csv')
df1 = pd.DataFrame(np.subtract(df['Close'], df['Close']), df.Date, df.Date)
print(df1)
Result:
Date 1987-01-02 1987-01-05 1987-01-06 1987-01-07 1987-01-08
Date
1987-01-02 NaN NaN NaN NaN NaN
1987-01-05 NaN NaN NaN NaN NaN
1987-01-06 NaN NaN NaN NaN NaN
1987-01-07 NaN NaN NaN NaN NaN
1987-01-08 NaN NaN NaN NaN NaN