I am a pandas newbie coming from a SQL background although have some exposure to Python.
I was wondering if there is a simple way to do the following SQL code in pandas dataframe:
Select
A,
Sum(B/C) value
From
Table
Group by
A
Below is all I got so far there doesn't seem to be a syntax to include arithmetic expressions:
df.groupby(['A']).sum()
Thanks in advance.
try this,
df.assign(value = df.B.div(df.C)).groupby('A')['value'].sum()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.