我正在寻找一种总结价值观的方法>;或者<;给定列中的某个阈值(此处为>;6天\u安装到\u事件列).
我try 了很多不同的方法,比如loc、query或groupby,但它只返回值>;6不是那些<;6.
以下是我try 过的一些事情:
df = pd.DataFrame({
'custom_action' : ['First_puchase', 'First_puchase', 'First_puchase', 'First_puchase',
'First_puchase', 'First_puchase', 'First_puchase', 'First_puchase'],
'days_install_to_event' : [1, 2, 3, 4, 5, 6, 7, 8],
'number_unique_users' : [1350, 250, 13, 2, 1, 2, 1, 2]})
df
custom_action days_install_to_event number_unique_users
0 First_puchase 1 1350
1 First_puchase 2 250
2 First_puchase 3 13
3 First_puchase 4 2
4 First_puchase 5 1
5 First_puchase 6 2
6 First_puchase 7 1
7 First_puchase 8 2
8 First_puchase 9 3
9 First_puchase 10 2
df_1 = df.loc[df['days_install_to_event'] > 6].sum()
df_2 = df.query("days_install_to_event > 6")['number_unique_users'].sum()
df_1
df_2
Output:
custom_action First_puchaseFirst_puchase
days_install_to_event 34
number_unique_users 8
8
Desired output:
custom_action days_install_to_event number_unique_users
0 First_puchase 1 1350
1 First_puchase 2 250
2 First_puchase 3 13
3 First_puchase 4 2
4 First_puchase 5 1
5 First_puchase 6 2
6 First_puchase 7+ 8
在此之前,如果有人问了一个非常类似的问题,我很抱歉.我在过go 的两天里一直在四处寻找,但没有发现任何与我想要的完全匹配的东西.这可能是由于配方.
谢谢你的帮助:)