i have a dataset which is a .txt file and each line has items separated by spaces. each line is a different transaction.
the dataset looks like this:
data.txt file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
20 12 5 41 65
41 6 11 27 81 21
65 15 27 8 31 65 20 19 44 29 41
i created a dictionary with keys as serial num. starting from 0 and each line values seperated by commas as values like this
{0: '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15', 1:'20,12,5,41,65', 2:'41,6,11,27,81,21', 3: '65,15,27,8,31,65,20,19,44,29,41'}
but i am not able to iterate through each value in dict , is there any way i can convert it into a list of values for each key
i want to find the frequency of each time in the whole dictionary and create a table
item | frequency |
---|---|
1 | 1 |
2 | 1 |
20 | 2 |
41 | 3 |
like the above
my_dict = {}
with open('text.csv', 'r') as file:
lines = file.readlines()
for line in lines:
my_dict[lines.index(line)] = line.strip()
this is the code i used to create the dictionary but i am not sure what i should change, also i need to find frequency of each value.
Any help would be appreciated. thank u.