Reading csv containing a list in Pandas

Viewed 24641

I'm trying to read this csv into pandas

HK,"[u'5328.1', u'5329.3', '2013-12-27 13:58:57.973614']"
HK,"[u'5328.1', u'5329.3', '2013-12-27 13:58:59.237387']"
HK,"[u'5328.1', u'5329.3', '2013-12-27 13:59:00.346325']"

As you can see there are only 2 columns and the second one is a list, is there a way to interpret it correctly ( meaning reading the values in the list as columns) when using pd.read_csv() with arguments ?

thank you

4 Answers
df['new_column'] = df['column'].apply(lambda x: ast.literal_eval(x))

Just run the above code on the column containing list as string.

Related