One of the columns of a CSV file is a list of timestamps. eg.,
[Timestamp('2015-01-15 16:37:00'), Timestamp('2016-04-25 16:37:00'), Timestamp('2017-08-20 16:37:00')]
When I am reading the CSV, I want this column to be read like a list of timestamps.
I am trying to write an apply function to convert the column which is string of list of timestamps as above to a list of DateTime timestamps using the ast library. However, I get the following error
ValueError: malformed node or string: <_ast.Call object at 0x0000023FBDC77748>
I have the reproducible code below
import ast
x = "[Timestamp('2015-01-15 16:37:00'), Timestamp('2016-04-25 16:37:00'), Timestamp('2017-08-20 16:37:00')]"
y = ast.literal_eval(x)
EDIT: As indicated in one of the answers below, I tried eval()
x = "[Timestamp('2015-01-15 16:37:00'), Timestamp('2016-04-25.16:37:00'), Timestamp('2017-08-20 16:37:00')]"
y = eval(x)
I get the following error:
y = eval(x)
File "<string>", line 1, in <module>
NameError: name 'Timestamp' is not defined