Pandas, for each unique value in one column, get unique values in another column

后端 未结 3 512
情话喂你
情话喂你 2020-12-25 08:01

I have a dataframe where each row contains various meta-data pertaining to a single Reddit comment (e.g. author, subreddit, comment text).

I want to do the following

3条回答
  •  春和景丽
    2020-12-25 08:46

    By using sacul's sample data

    df['subreddit'].groupby(df['author']).unique().apply(pd.Series)
    Out[370]: 
              0    1
    author          
    a       sr1  sr2
    b       sr2  NaN
    

提交回复
热议问题