Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Read a column containing a list as a list
# Reference: python - Reading csv containing a list in Pandas - Stack Overflow https://stackoverflow.com/questions/20799593/reading-csv-containing-a-list-in-pandas
# Copy this text.
"""
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']"
"""
import ast
import pandas as pd
df = pd.read_clipboard(header=None, quotechar='"', sep=',', converters={1:ast.literal_eval})
# 0 1
# 0 HK [5328.1, 5329.3, 2013-12-27 13:58:57.973614]
# 1 HK [5328.1, 5329.3, 2013-12-27 13:58:59.237387]
# 2 HK [5328.1, 5329.3, 2013-12-27 13:59:00.346325]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.