1

I have a dataframe like this -

Folder    FileName 
A            1
B            2
C            1

And I want to create one like this, which counts the occurence of each file in each folder -

FileName A B C
   1     1 0 1
   2     0 1 0

Is there an intuitive way to achieve this?

Mbaps
  • 143
  • 1
  • 1
  • 11

1 Answers1

1

try this,

print pd.crosstab(df['Folder'],df['FileName']).T

As @coldspeed suggests,

print pd.crosstab(df['FileName'],df['Folder']) #more convenient way
Mohamed Thasin ah
  • 10,754
  • 11
  • 52
  • 111