I'm fairly new to Python and Pandas, I'm trying to pull some statistics from a Series. I want to calculate the difference between the last row and the first row, and put that in a new Series.
My first series looks similar to this:
# Symbol(1) Symbol(2) Symbol(3)
Mon 5 10 15
Tue 6 9 12
Wed 3 11 15
I would like to know how to easily create this resultant Series:
# Symbol(1) Symbol(2) Symbol(3)
Diff -2 1 0
This is the latest iteration of the code I tried:
diffy = pd.concat([inputs.head(1),inputs.tail(1)])
diffy.dropna(axis='columns', inplace='true')
a = pd.Series(index=diffy.index)
for c in diffy.columns:
a.append(pd.Series(data=[diffy[c][1]-diffy[c][0]], index=c))
However, I get a TypeError
on the last line, where I try to append the information.
This question seems to be a very similar issue, but the accepted answer doesn't quite provide the full details.