I used text mining to capture word counts from various documents. In doing so, I search a given list of words in the texts. Example: data, digital & wifi
My code outputs a dictionary with the matched word (key) and count (value) as a result. Example:
txt_file_1: {'data': 2, 'digital': 1}
txt_file_2: {'data': 3}
Now I want to transfer that into a dataframe by listing all the words I searched for in the first column. The other columns should output the txt_file and the corresponding matches as header (see table below).
My question is: How do I match the keys from the dictionary with the related entries in the first column so that the values end up correctly?
| words | txt_file_1 | txt_file_2 |
|---|---|---|
| data | 2 | 3 |
| digital | 1 | 0 |
| wifi | 0 | 0 |