I am trying to get group by and count in python. It does not seem to group for some reason
Using python 2.7
#!/usr/bin/env python
counts = {}
logfile = open("/tmp/test.out", "r")
for line in logfile:
if line.startswith("20") in line:
seq = line.strip()
substr = seq[0:13]
if substr not in counts:
counts[substr] = 0
counts[substr] += 1
for substr, count in counts.items():
print(count,substr)
I would like output like below grouped by count
6 2019-06-17T00
13 2019-06-17T01
9 2019-06-17T02
7 2019-06-17T03
6 2019-06-17T04
2019-06-19T09:56:04.378+0000: [Times: user=153.84 sys=1.15, real=18.13 secs] 2019-06-19T09:59:46.370+0000: [Times: user=154.93 sys=1.24, real=18.65 secs]2019-06-19T10:00:05.074+0000: [Times: user=155.21 sys=1.39, real=20.03 secs]('2019-06-16T10', 1) ('2019-06-15T19', 1) ('2019-06-16T13', 1) ('2019-06-16T12', 1)