「連結」という名前のデータフレームがあります。列があります: 'amount' - トランザクションの合計、'mcccode_trtype' はマーチャント タイプです。商人コードごとに負の金額のトランザクションのみをカウントし、これらのトランザクションの平均をカウントする必要があります。また、トランザクション数が 10 を超えるマーチャントをフィルタリングする必要があります。
だから、私はこのコードを書きました:
res=concated[concated.amount<0].groupby('mcccode_trtype')['amount'].agg(['count', 'mean'])
問題: これを 1 行の「カウント」列でフィルタリングするにはどうすればよいですか? 「フィルター」+ラムダ関数を使用する必要があると思いますが、最終的に構文で失敗しました。
助けてください。
サンプルデータ:
from numpy import nan
concated=pd.DataFrame(
{0: {'amount': -2245.92,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '0 10:23:26',
'tr_description': 'DESCR2',
'tr_type': 1030},
1: {'amount': -5614.79,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '6 07:08:31',
'tr_description': 'DESCR2',
'tr_type': 1030},
2: {'amount': -1122.96,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '8 07:06:10',
'tr_description': 'DESCR2',
'tr_type': 1030},
3: {'amount': -2245.92,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '11 08:49:03',
'tr_description': 'DESCR2',
'tr_type': 1030},
4: {'amount': -2245.92,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '11 14:12:08',
'tr_description': 'DESCR2',
'tr_type': 1030},
5: {'amount': -2245.92,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '11 14:15:30',
'tr_description': 'DESCR2',
'tr_type': 1030},
6: {'amount': -2245.92,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '13 11:17:34',
'tr_description': 'DESCR2',
'tr_type': 1030},
7: {'amount': -2245.92,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '18 07:39:05',
'tr_description': 'DESCR2',
'tr_type': 1030},
8: {'amount': -449.18,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '19 13:24:35',
'tr_description': 'DESCR2',
'tr_type': 1030},
9: {'amount': -1122.96,
'customer_id': 39026145,
'gender': 1.0,
'mcc_code': 4814,
'mcc_description': 'DESCR1',
'mcccode_trtype': '48141030',
'term_id': nan,
'tr_datetime': '19 13:25:31',
'tr_description': 'DESCR2',
'tr_type': 1030}}).transpose()
concated