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

前端 未结 5 770
无人及你
无人及你 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:55

    I did it this way:

    df = pd.read_clipboard(sep='\s{2,}', engine='python')
    df = df.apply(lambda x: x.str.replace(r'[\[\]]*', '').str.split(',\s*', expand=False))
    

    PS i'm sure - there must be a better way to do that...

提交回复
热议问题