1

I have this code after filtering a CSV file:

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)

But I'm stuck here when the csv looks like:

Type     Assignee        status

request  madan          assigned

ris      madan          resolved

request  kumar          resolved

incide   kumar          assigned

incide   madan          assigned

I need output as:

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

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

Please Help. Thanks in advance.

1 Answer 1

1

You can use crosstab in pandas

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

Output:

          assigned  resolved  incide  request  ris
Assignee
kumar            1         1       1        1    0
madan            2         1       1        1    1
Sign up to request clarification or add additional context in comments.

3 Comments

pd.concat([pd.crosstab(df['Assignee+'], df['Status*']), pd.crosstab(df['Assignee+'], df['Case Type*']], axis=1))
Yes, you are right, df['colname'] is a formal way and df.colname is more of a syntax sugar with limitations in column namings. It is generally not a good idea to include spaces, + or - signs in column names since as you experienced the syntax sugar does not work anymore.
Your first comment is the way :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.