Skip to content

Instantly share code, notes, and snippets.

@Keiku
Created June 28, 2020 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keiku/0e40822af48874dd6134acc24fcc3054 to your computer and use it in GitHub Desktop.
Save Keiku/0e40822af48874dd6134acc24fcc3054 to your computer and use it in GitHub Desktop.
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