I am having a difficult time trying to use the python's agg function - which as I have learned - is similar to R's summarise function
I have the following dataset:
ID Date Qtr Price Fee_Rate
1 1/1/10 1 10 1.002
1 1/2/10 1 10.3 1.002
1 1/3/10 1 10.4 1.002
2 1/1/10 1 25 .987
2 1/2/10 1 23.4 .987
... ... ... ... ...
1 4/1/10 2 12.4 1.09
1 4/2/10 2 12.5 1.09
and so on..
Essentially - I want to group by Quarter, filter to the first date of the quarter, and summarise (Price*Fee_Rate)
In R - the code is as below
df %>% group_by(Qtr) %>% filter(Date == min(Date) %>% summarise( L_Value = sum(Price*Fee_Rate))
How would I go replicating this syntax in Python?
This is what I have tried so far:
df.groupby('Qtr').head(1).agg({'L_Value' : ('Price'*'Fee_Rate').sum())})
but it doesn't work, giving the following error:
can't multiply sequence by non-int of type 'str'
Which I assume is because of 'Price' * 'Fee_Rate'..
Thanks!