0

I have been struggling to do this without pandas.
Can anybody help?

ID,Name,timstamp,IN_OR_OUT,Date
103161,John Alex,15-10-2018 10:51:01,IN,15-10-2018
103161,John Alex,15-10-2018 11:31:00,OUT,15-10-2018
103161,John Alex,15-10-2018 11:32:07,IN,15-10-2018
103161,John Alex,15-10-2018 11:38:07,OUT,15-10-2018
103161,John Alex,15-10-2018 11:43:03,IN,15-10-2018
103161,John Alex,15-10-2018 13:00:08,OUT,15-10-2018 
103161,John Alex,15-10-2018 13:46:07,IN,15-10-2018
103161,John Alex,15-10-2018 14:28:04,OUT,15-10-2018
103161,John Alex,15-10-2018 14:29:04,IN,15-10-2018
103161,John Alex,15-10-2018 15:08:06,OUT,15-10-2018
103161,John Alex,15-10-2018 15:12:03,IN,15-10-2018
103161,John Alex,15-10-2018 15:54:00,OUT,15-10-2018
103161,John Alex,15-10-2018 15:58:00,IN,15-10-2018
103161,John Alex,15-10-2018 16:01:00,OUT,15-10-2018
103161,John Alex,15-10-2018 16:15:06,IN,15-10-2018
103161,John Alex,15-10-2018 17:33:02,OUT,15-10-2018
103161,John Alex,15-10-2018 17:34:02,IN,15-10-2018
103161,John Alex,15-10-2018 17:45:04,OUT,15-10-2018 

So I want the final output to be like this

ID,Name,timstamp,IN,OUT,Date
103161,John Alex,15-10-2018 10:51:01,15-10-2018 11:31:00,15-10-2018
103161,John Alex,15-10-2018 11:32:07,15-10-2018 11:38:07,15-10-2018
103161,John Alex,15-10-2018 11:43:03,15-10-2018 13:00:08,15-10-2018
103161,John Alex,15-10-2018 13:46:07,15-10-2018 14:28:04,15-10-2018
103161,John Alex,15-10-2018 14:29:04,15-10-2018 15:08:06,15-10-2018

I know we can achieve this using pandas but is there anyway we can do this without pandas?

Space Impact
  • 13,085
  • 23
  • 48
Mahesh
  • 75
  • 2
  • 9

1 Answers1

0

Assuming all your input lines are stored in lines and they are ordered, i.e. consecutive entries belong together, then this is the solution:

for k, line in enumerate(lines):
    if not k % 2:
        out_line = line
    else:
        print(out_line.replace('IN', line.split(',')[2]))
rammelmueller
  • 1,092
  • 1
  • 14
  • 29