I have a huge df
which has a doc_id
and word
, and every word
can contain multiple class(Class_1,Class_2,Class_3 )
so if a word is in that class
i put 1
there or if not then 0
SAMPLE DF
doc_id word Class_1 Class_2 Class_3
104 saturn 1 0 1
104 survival 1 1 0
104 saturn 1 0 1
104 car 0 1 0
118 baseball 1 1 0
118 color 0 0 1
118 muscle 0 1 0
187 image 1 0 0
187 pulled 0 0 0
187 game 1 0 1
187 play 0 0 1
187 game 1 1 0
125 translation 1 0 0
125 survival 0 1 0
125 input 1 0 1
125 excellent 1 0 0
142 nice 0 1 0
142 article 0 1 0
142 original 1 0 1
142 content 0 1 0
Now using this sample DF
i want to count
number of Occurrences of word
in class(Class_1,Class_2,Class_3)
.
Total words in each class(Class_1,Class_2,Class_3)
, eg:
like how many words
are there in Class_1
and lastly total unique words
in all documents.
OUTPUT DF should be something like this
doc_id word Occ_1 Occ_2 Occ_3 Totl_1 Totl_2 Totl_3 Unique_words
104 saturn 2 0 2 11 9 7 17
104 survival 1 2 0 11 9 7 17
104 car 0 1 0 11 9 7 17
118 baseball 1 1 0 11 9 7 17
118 color 0 0 1 11 9 7 17
118 muscle 0 1 0 11 9 7 17
187 image 1 0 0 11 9 7 17
187 pulled 0 0 0 11 9 7 17
187 game 2 1 1 11 9 7 17
187 play 0 0 1 11 9 7 17
125 translation 1 0 0 11 9 7 17
125 input 1 0 1 11 9 7 17
125 excellent 1 0 0 11 9 7 17
142 nice 0 1 0 11 9 7 17
142 article 0 1 0 11 9 7 17
142 original 1 0 1 11 9 7 17
142 content 0 1 0 11 9 7 17
Whereas
Occ_1
= Number of Occurrences of Word in Class_1
and same for other Class_2
and Class_3
Totl_1
= Total Words in Class_1
and same for other Class_2
and Class_3
Unique_words
= Number of Total Unique Words in All Documents