last day (15 days later) » 

2:01 PM
1
A: Pandas pivot table - show values under same column index

jezraelFirst convert from dictionary one elemment lists to strings for avoid 3 level MultiIndex: f = {'Balance': 'sum', 'WAP': 'mean'} And then use DataFrame.swaplevel with DataFrame.sort_index: f = {'Balance': 'sum', 'WAP': 'mean'} df = (df.pivot_table( columns='Delivery', values=['Balance...

 
dear @jezrael thank you for helping me out. however, i wish to achieve the final df in my question (i have just edited it for more clarity) where the 2 values Balance and WAP are shown on a shared column index of Delivery
 
@yongsheng - Answer was edited.
 
amazing.. thank you so much for your help i appreciate it
dear @jezrael, I realized that my Weighted Average Price calculation is wrong. Have edited my question to add WAP function and np.average function to calculate new weighted average price, but both are wrong.. would appreciate any guidance
 
@yongsheng - There is problem I solve your reshape problem, not count problem.
@yongsheng - Is possible add expected output for verify?
 
very sorry am not sure if i should post new question for count problem.. one second and let me add expected output
 
2:01 PM
@yongsheng - Not so easy, but need some time.
ya
I try check some solutions
but fialed
66
A: groupby weighted average and sum in pandas dataframe

jrjcTo pass multiple functions to a groupby object, you need to pass a dictionary with the aggregation functions corresponding to the columns: # Define a lambda function to compute the weighted mean: wm = lambda x: np.average(x, weights=df.loc[x.index, "adjusted_lots"]) # Define a dictionary with t...

 
Hi @jezrael have done a quick expected output , not sure if enough .. if you need me to post a new question i will do it
 
26
Q: Calculate weighted average using a pandas/dataframe

mike01010I have the following table. I want to calculate a weighted average grouped by each date based on the formula below. I can do this using some standard conventional code, but assuming that this data is in a pandas dataframe, is there any easier way to achieve this rather than through iteration? ...

I think yes
And for 100% I not answering it
 
i will do so, with new dataframe .. thank you very much for all your help, i appreciate it
 
You are welcome. Btw, maybe add 1, 2 values to expected output
in your new question
 
okay.. very sorry if have made you angry. will do so later.. thank you
 
2:07 PM
no, Iam very happy
because you give me commnet
explanation
chating
so I hope you are OK too ;)
 

last day (15 days later) »