Question: I want to find pandas equivalent of sql...

```
select sum(t.col1 * t.col2) / sum(t.col3) from table as t group by t.col4

```

I did

```
df.groupby(['col4'])[['col3']].sum()

```

but it only produce the sum(t.3)...

is there a one-line statement to achieve this kind of task in pandas?

Answer: 
Try:

```py
df['n'] = df['col1'].mul(df['col2'])
gr = df.groupby(['col4'])
res = gr['n'].sum().div(gr['col3'].sum())

```
Try this:

```
df_grouped = df.groupby(['col4'])
col1 = df_grouped['col1']
col2 = df_grouped['col2']
col3 = df_grouped['col3']
col1col2 = col1.mul(col2).sum()
res = col1col2.div(col3.sum())

```

I'm not sure if it's correct or not but I hope it helps.