data science with r

Discussion in 'General Discussions' started by Vivek Chopra, Mar 3, 2020.

  1. Vivek Chopra

    Vivek Chopra New Member

    Joined:
    Aug 22, 2019
    Messages:
    1
    Likes Received:
    0
    Hi,
    I have a question how can we subset a data frame based on same id but different purchases.
     
    #1
  2. Kunal Guwalani

    Kunal Guwalani Well-Known Member
    Simplilearn Support

    Joined:
    Jul 17, 2018
    Messages:
    198
    Likes Received:
    20
    Please try to code below:


    counts = df['CustID'].value_counts()
    df[df['CustID'].isin(counts.index[counts >1])]

    -----------------------------------------------------------------------

    df[df['CustID'].duplicated(keep=False)]

    ---------------------------------------------------------------------

    df.groupby('CustID').filter(lambda x: len(x)>1)
     
    #2

Share This Page