我在csv文件中有以下内容
key1 key2 Key3 key4 key5
Val1 A 51 'True' 25
Val1 A 50 'False' 25
Val1 A 49 'True' 25
Val1 A 48 'True' 25
Val2 A 47 'False' 25
Val2 A 46 'True' 25
Val2 A 45 'False' 25
Val2 A 44 'True' 25
Val2 A 43 'True' 25
输出应类似
key1 key2 max_key5 total_key4 total_true_key4
Val1 A 51 4 3
Val2 A 47 5 3
我必须按键1和键2分组,然后找到键5的最大值、键4的总行数和键4的总真行数
我在try 什么
print(json_data.groupby(["key1","key2"]).agg(
max_key5=('key5','max'),
total_key4=('key4','count'),
total_true_key4 = ("key4", lambda x: count(x == 'TRUE'))
))
我也试过像belwo一样
print(json_data.groupby(["section","row"]).agg(
max_key5=('key5','max'),
total_skey4=('key4','count'),
total_true_key4 = pd.NamedAgg(
column="key4",
aggfunc=lambda x: (x == True))
))
我没有得到total\u true\u key4的正确值
非常感谢您的任何建议..
谢谢