How to group set of time under distinct date from csv file
<p>hi i have just gotten a set of time and date data from csv file using regex:</p>

<pre><code>datePattern = re.compile(r"(\d+/\d+/\d+\s+\d+:\d+)")
for i, line in enumerate(open('sample_data.csv')):
    for match in re.finditer(datePattern, line):
        date.append(match.groups());
</code></pre>

<p>the output is [('30/06/2016 08:30',), ('20/07/2016 09:30',), 
('30/06/2016 07:30',)</p>

<p>How do i turn it into useful information such as listing all the time under the same date such as maybe  [('30/06/2016 08:30',07.30),]</p>

<p>Try this regex:</p>

<pre><code>r"(\d+/\d+/\d+)\s+(\d+:\d+)"
</code></pre>

<p><a href="https://repl.it/DrqS/2" rel="nofollow">Python code</a> follows, I have used dictionary of lists for such grouping</p>

<pre><code>import re

datePattern = re.compile(r"(\d+/\d+/\d+)\s+(\d+:\d+)")  
dateDict =dict()    

for i, line in enumerate(open('sample_data.csv')):
    for match in re.finditer(datePattern,line):
        if match.group(1) in dateDict:
            dateDict[match.group(1)].append(match.group(2))
        else:
            dateDict[match.group(1)] = [match.group(2),]        
print(dateDict)         
</code></pre>

<p>It will output as follows:</p>

<pre><code>{'10/10/1990': ['12:20', '11:20'], '10/10/1991': ['16:20', '16:20']}

Tested with python 3+
</code></pre>

python regex