Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- df = pd.DataFrame([["row1",50, 200],["row2",100, 300]], columns=list('ABC'))
- print(df)
- print("nn")
- pivot = df.pivot_table(
- index=["A"],
- columns=[],
- values=["B", "C"],
- aggfunc={
- "B": np.sum,
- "C": np.sum,
- },
- margins=True,
- margins_name = "Total",
- fill_value=0
- )
- print(pivot)
- B C
- A
- row1 50 200
- row2 100 300
- Total 150 500
- B C D E
- A
- row1 50 200 250 38.46%
- row2 100 300 400 61.54%
- Total 150 500 650 100%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement