I am new to python. I have the following data frame. I am able to pivot in Excel.
I want to add the difference column(in the image, I added it manually).
The difference is B-A value. I am able to replicate except difference column and Grand Total using Python pivot table. Below is my code.
table = pd.pivot_table(data, index=['Category'], values = ['value'], columns=['Name','Date'], fill_value=0)
How can I add the difference column and calculate the value?
How can I get Grand Total at the bottom?
Data as below
df = pd.DataFrame({
"Value": [0.1, 0.2, 3, 1, -.5, 4],
"Date": ["2020-07-01", "2020-07-01", "2020-07-01", "2020-07-01", "2020-07-01", "2020-07-01"],
"Name": ['A', 'A', 'A', 'B', 'B', 'B'],
"HI Display1": ["X", "Y", "Z", "Z", "Y", "X"]})
I want to the pivot table as below