Get All Unique Values in a Row

前端 未结 3 420
陌清茗
陌清茗 2021-01-12 04:58

I have a DataFrame df1 that looks like this:

A       B       C
-----------------
1       1       2
2       2       3
5       4       9
         


        
3条回答
  •  悲&欢浪女
    2021-01-12 05:36

    In [88]: df.stack().groupby(level=0).apply(lambda x: x.unique().tolist())
    Out[88]:
    0       [1, 2]
    1       [2, 3]
    2    [5, 4, 9]
    dtype: object
    

提交回复
热议问题