gpt4 book ai didi

python - python pandas 中的列和行中的多个过滤器

转载 作者:行者123 更新时间:2023-12-01 09:07:03 29 4
gpt4 key购买 nike

过滤 CSV 文件后我得到了以下代码:

import pandas as pd

data1=pd.read_csv('Report1.csv',encoding = "ISO-8859-1")

df = data1[pd.notnull(data1['Assignee'])]

group=(df['type'].value_counts())

print(group)

但是当 csv 看起来像这样时我被困在这里:

Type     Assignee        status

request madan assigned

ris madan resolved

request kumar resolved

incide kumar assigned

incide madan assigned

我需要输出为:

madan has 2 assigned and 1 resolved (1  request, 1 ris , 1 inciden)

kumar has 1 assigned and 1 resolved (1 request , 1 incident )

请帮忙。提前致谢。

最佳答案

您可以在pandas中使用crosstab

pd.concat([pd.crosstab(df.Assignee, df.status), pd.crosstab(df.Assignee, df.Type)], axis=1)

输出:

          assigned  resolved  incide  request  ris
Assignee
kumar 1 1 1 1 0
madan 2 1 1 1 1

关于python - python pandas 中的列和行中的多个过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51958993/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com