0

Here is how I turn a string into a datetime format:

import datetime
timest = '2017-05-05 16:55:27.639'
t = datetime.datetime.strptime(timest, '%Y-%m-%d %H:%M:%S.%f')

Now, let's say I have a dataframe like this one:

import pandas as pd
  
datas = {
  'Action': ['Action1', 'Action2', 'Action1', 'Action1', 'Action2'],
  'Timestamp': ['2017-05-05 16:55:27.639', '2017-05-05 16:55:27.733', '2017-05-05 16:55:27.795', '2017-05-05 16:55:27.873', '2017-05-05 16:55:27.951'],}
  
df = pd.DataFrame(datas, columns = ['Action', 'Timestamp'])

I'd like to apply the string -> datetime operation on all values of the "Timestamp" column. The ways to apply a specific operation on all the values of a dataframe I've seen don't seem to work since it involves putting a pandas.Series as a parameter of the strptime instead of a string.

MVMV
  • 37
  • 6

0 Answers0