pandas - convert string into list of strings

前端 未结 6 1810
故里飘歌
故里飘歌 2020-12-15 22:50

I have this \'file.csv\' file to read with pandas:

Title|Tags
T1|\"[Tag1,Tag2]\"
T1|\"[Tag1,Tag2,Tag3]\"
T2|\"[Tag3,Tag1]\"

using



        
6条回答
  •  独厮守ぢ
    2020-12-15 23:27

    You can convert the string to a list using strip and split.

    df_out = df.assign(Tags=df.Tags.str.strip('[]').str.split(','))
    
    df_out.Tags[0][0]
    

    Output:

    'Tag1'
    

提交回复
热议问题