Код: Выделить всё
def monthly_transactions(transactions: pd.DataFrame) -> pd.DataFrame:
df = transactions.groupby([pd.Grouper(key='trans_date', freq='M') ,'country', ],
as_index = False).agg(
trans_count = ('trans_date', 'size'),
approved_count = ('state', lambda x: (x == 'approved').sum()),
trans_total_amount = ('amount', 'sum'),
approved_total_amount=('amount', lambda x: x[transactions['state'] == 'approved'].sum())
).rename(columns = {'trans_date' : 'month'})
df['month'] = df['month'].dt.to_period('M')
#print(df) -> shows the correct solution
return df # -> throws OverflowError: Maximum recursion level reached
Подробнее здесь: https://stackoverflow.com/questions/791 ... sactions-i