2 回答
TA贡献1816条经验 获得超6个赞
编辑:这将使模型保持流失率 > 80%
import pandas as pd
df = pd.pivot_table(df, index='model id', columns='churn flag', aggfunc='sum', fill_value=0).reset_index()
df.columns=['model id', 'N', 'Y']
df['churn rate'] = df['Y'] / (df['N'] + df['Y'])
df = df[df['churn rate']>0.8]
TA贡献1829条经验 获得超7个赞
看看这是否有帮助:
import pandas as pd
df = pd.DataFrame({'Model Id': ['102', '102', '1094', '2017p','225','225','250U','3000'], 'churn flag': ['N','Y','Y','N','N','Y','N','N'], 'count':[10,2,1,12,37,1,60,6]})
dict(iter(df.groupby('churn flag')))
这会给你
{'N': Model Id churn flag count
0 102 N 10
3 2017p N 12
4 225 N 37
6 250U N 60
7 3000 N 6,
'Y': Model Id churn flag count
1 102 Y 2
2 1094 Y 1
5 225 Y 1}
这是你要找的吗?
添加回答
举报