pandas - convert string into list of strings

前端 未结 6 1819
故里飘歌
故里飘歌 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:25

    You can split the string manually:

    >>> df['Tags'] = df.Tags.apply(lambda x: x[1:-1].split(','))
    >>> df.Tags[0]
    ['Tag1', 'Tag2']
    

提交回复
热议问题