Created
June 28, 2020 06:57
-
-
Save Keiku/0e40822af48874dd6134acc24fcc3054 to your computer and use it in GitHub Desktop.
Read a column containing a list as a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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