python - pandas - convert string into list of strings -


i have 'file.csv' file read pandas:

title|tags t1|"[tag1,tag2]" t1|"[tag1,tag2,tag3]" t2|"[tag3,tag1]" 

using

df = pd.read_csv('file.csv', sep='|') 

the output is:

  title              tags 0    t1       [tag1,tag2] 1    t1  [tag1,tag2,tag3] 2    t2       [tag3,tag1] 

i know column tags full string, since:

in [64]: df['tags'][0][0] out[64]: '[' 

i need read list of strings ["tag1","tag2"]. tried solution provided in this question no luck there, since have [ , ] characters mess things.

the expecting output should be:

in [64]: df['tags'][0][0] out[64]: 'tag1' 

you can split string manually:

>>> df['tags'] = df.tags.apply(lambda x: x[1:-1].split(',')) >>> df.tags[0] ['tag1', 'tag2'] 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -