How to read a column of csv as dtype list using pandas?

后端 未结 5 861
名媛妹妹
名媛妹妹 2020-12-02 22:58

I have a csv file with 3 columns, wherein each row of Column 3 has list of values in it. As you can see from the following table structure

Col1,Col2,Col3
1,a         


        
5条回答
  •  时光说笑
    2020-12-02 23:23

    Adding a replace to Cunninghams answer:

    df = pd.read_csv("in.csv",converters={"Col3": lambda x: x.strip("[]").replace("'","").split(", ")})
    

    See also pandas - convert string into list of strings

提交回复
热议问题