Entering edit mode
7.9 years ago
ahmedakhokhar
▴
150
I am working with a tab separated files:
A B C D
a d ii domain
a d g domain
a h g domain
a i k motif
c i k motif
c g ii motif
v g p domain
Question: I want to count each entry in first column and all related entry to it in second, third and fourth column like:
a 4 d 2 h 1 i 1 ii 1 k 1 domain 3 motif 1
c 2 i 1 g 1 k 1 ii 1 motif 2
v 1 g 1 p 1 motif 1
I am trying to sort this data with python pandas by these commands:
df = pd.read_csv('file.txt', delimiter= '\t', names = ['A', 'B', 'C', 'D'])
df1.groupby(['a', 'c', 'd', 'e']).count()
but it does not return the desired results.
Any help would be appreciated, thanks.