Answers for "pandas read csv dtype list"

0

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
Posted by: Guest on January-12-2022

Python Answers by Framework

Browse Popular Code Answers by Language