How do you read in a dataframe with lists using pd.read_clipboard?

前端 未结 5 797
无人及你
无人及你 2021-01-05 00:33

Here\'s some data from another question:

                          positive                 negative          neutral
1   [marvel, moral, bold, destiny]              


        
5条回答
  •  时光取名叫无心
    2021-01-05 00:48

    Another alternative is

    In [43]:  df.applymap(lambda x: x[1:-1].split(', '))
    Out[43]: 
                             positive                negative         neutral
    1  [marvel, moral, bold, destiny]                      []  [view, should]
    2                     [beautiful]     [complicated, need]              []
    3                     [celebrate]  [crippling, addiction]           [big]
    

    Note that this assumes the first and last character in each cell is [ and ]. It also assumes there is exactly one space after the commas.

提交回复
热议问题