-2

I have a big .csv file which holds machine log data. One of the fields is timestamp. It stores date and time as shown in the title and I would like to drop the milli seconds and convert it into the format also shown in title. Can anyone help me with that? Im new to Python and Ipython.

Much obliged.

Thomas K
  • 39,200
  • 7
  • 84
  • 86
Azee.
  • 703
  • 1
  • 5
  • 12
  • 2
    Think about it. That would amount to replacing the character `T` with a space in the timestamp string, and removing everything after the last dot (including the dot itself). Are you sure you don't know how to do that (even after searching around a little)? – Frédéric Hamidi Feb 23 '15 at 15:32
  • I should have mentioned that I literally started working with python and the Ipython notebook today, lol took me thirty mins to figure out if I want to import a csv to a data frame i need to put an r before the file path. Guess I was jusst being lazy. anyhoo, thanks for your input. :) – Azee. Feb 23 '15 at 15:41

2 Answers2

0

For your special case, this should suffice:

t.replace('T', ' ')[:19]

But I would recommend, that you use the datetime module of the standard library instead, so your time conversion also could be internationalized.

Juergen
  • 12,378
  • 7
  • 39
  • 55
0

You can use easy_date to make it easy:

import date_converter
new_date = date_converter.string_to_string("2013-01-06T22:25:08.733", "%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%d %H:%M:%S")
Raphael Amoedo
  • 4,233
  • 4
  • 28
  • 37