I would like to make some calculations with the dataframe

| ID | Method | Country | Amount | Success |
| --- | --- | --- | --- | --- |
| 95 | Мир | Belarus | 6063 | 0 |
| 96 | Maestro | Japan | 4013 | 0 |
| 97 | American Express | Belarus | 1426 | 1 |
| 98 | Maestro | Belarus | 5692 | 1 |
| 99 | Mastercard | Russia | 6929 | 1 |

I would like to calculate average amount by Method and Country, number of payment, Success Rate and total amount of successful payments.

```
Success Rate = (Number of payments where Success = 1) / All payments

```

In SQL I would do this amazingly simple

```
    SELECT country,
           method,
           avg(amount),
           count(1),
           count(CASE WHEN success = 1 THEN id END) / count(1) AS conversion, 
sum(CASE WHEN success = 1 THEN amount END) sum_success, 
    FROM data
    GROUP BY country, method;

```

First two calculations are relatively simple in Python too.

```
df.groupby(['Country', 'Method']).agg({'Amount': ['mean', 'count']})

```

But the third, fourth calculations seems kinda impossible without a lot of effort.

Is there a way to do it quickly and elegant?

Please don't say that I could calculate Success Rate by taking mean() of Success column. I know that. I've simplified what I actually going to do and my real task couldn't be solved this way.