Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas read csv dtype list

from ast import literal_eval
df = pd.read_csv("in.csv",converters={"Col3": literal_eval})

# Or, if you are sure the format is the same for all strings, stripping and splitting will be a lot faster:
df = pd.read_csv("in.csv",converters={"Col3": lambda x: x.strip("[]").split(", ")})
# But you will end up with the strings wrapped in quotes
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #read #csv #dtype #list
ADD COMMENT
Topic
Name
8+4 =