0
[enter image description here][1]

my data frame is like this EMPLOYEE_ID 2020-02-26 2020-02-27 2020-02-28 2020-02-29 2020-03-01 100000074 Absent Absent Absent Present Absent 100000086 No Match No Match Absent Present Absent

and want to be like

EMPLOYEE_ID     Absent  Present  No Match 
100000074       4         1        0

Plz help

1
  • 2
    Stack Overflow is not a coding service. Please show some effort and request for some help, not code! Commented Mar 16, 2020 at 8:28

1 Answer 1

1

Use DataFrame.melt with DataFrame.pivot_table:

df1 = (df.melt('EMPLOYEE_ID')
         .pivot_table(index='EMPLOYEE_ID', columns='value', aggfunc='size', fill_value=0)
         )
print (df1)
value        Absent  No Match  Present
EMPLOYEE_ID                           
100000074         4         0        1
100000086         2         2        1

Another solution with Series.value_counts per rows in DataFrame.apply:

df1 = (df.set_index('EMPLOYEE_ID').apply(lambda x: x.value_counts(), axis=1)
         .fillna(0)
         .astype(int))
print (df1)
             Absent  No Match  Present
EMPLOYEE_ID                           
100000074         4         0        1
100000086         2         2        1
Sign up to request clarification or add additional context in comments.

1 Comment

@SanjayGhosh - ya, maybe in future is better add some code, what you try to question for avoid downvotes.

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.