0

I have a Df which looks like this:-

    tests machine
    A     mac1
    A     mac1
    A     mac2
    A     mac2
    B     mac1
    B     mac1
    B     mac3
    C     mac3
    C     mac3

Using this Df i want create a Dataframe which looks like this:

    No_of_tests   mac1 mac2 mac3
    A             2    2    0     #test A is done 2 times on mac1, 2 times on mac2 and so on
    B             2    1    0     #test B is done 2 times on mac1, 1 time on mac2 and so on
    C             0    0    2     #test C is done 0 times on mac1, 0 times on mac2 and so on  

Can somebody help me create this matrix using the Dataframe above.

nivedan gowda
  • 205
  • 2
  • 9

1 Answers1

1

IICU

 df.groupby('tests')['machine'].value_counts().unstack('machine', fill_value=0).reset_index()

enter image description here

wwnde
  • 26,119
  • 6
  • 18
  • 32