0

I am reading some data from a .tsv file with python using standard method but even though it reads strings somehow my date and time format changes from "4/4/2019 6:28:19 PM" to "4/4/2019 18:28". I am losing seconds and the AM/PM tags.

Using Python3 standard libraries. My data is tab separated like follows;

Col1\tTimeStamp\tCol2 val1\t4/4/2019 6:28:19 PM\tval2 

Here is my importData function

def importData(file): f = open(file, 'r', encoding='utf-8') headers, data = f.readline().rstrip('\n').split('\t'), [] for line in f: data += [line.rstrip('\n').split('\t')] f.close() return headers, data 

Update: When I opened the data with Excel and then applied formatting to the timestamp column, it read just fine. I will look into this further later but so far if anyone else have the same issue this could be a work around or the cause of the issue.

5
  • after line f = open(..), can you show us what is the output of print(repr(f.read()))? Commented May 15, 2019 at 1:14
  • It looks normal. What's causing that? Commented May 15, 2019 at 2:30
  • Had to edit my first comment I was dealing with the wrong data. Commented May 15, 2019 at 2:33
  • Update. I was using small portion of the data as a test and when I did repr() thing it looked normal and afterwards even though removed that line it was working fine. Now I am back with the original data and it's too big to fit into memory and repr() is not working. So I am still getting timestamps without the seconds and AM/PM. Commented May 15, 2019 at 10:08
  • Possibly helpful or related explanation datetime format change when save to csv file python Commented May 15, 2019 at 19:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.