I am trying to populate a dict with column-wise occurences of characters in pandas sereis. The sereis is as follows:
>>> jkl
1 ATGC
2 GTCA
3 CATG
Name: 0, dtype: object
I want a dict in a way that contains all the characters as keys and list of their column-wise occurence frequencies as value for the dict as shown below:
{'A':[1,1,0,1],'C':[1,0,1,1],'G':[1,0,1,1],'T':[0,2,1,0]}
I have tried several codes and this is one of them:
mylist = ['A', 'C', 'G','T']
dict = {key: None for key in mylist}
for i,(a,b) in enumerate(zip_longest(jkl[1],dict.keys())):
t=str(list(jkl.str[i]))
single_occurrences = Counter(t)
kl.append(single_occurrences.get(b))
dict[b]=kl
But this dict does not contain the desired output, is there a solution?