Pandas random sample with remove

前端 未结 2 1283
忘掉有多难
忘掉有多难 2021-02-04 08:31

I\'m aware of DataFrame.sample(), but how can I do this and also remove the sample from the dataset? (Note: AFAIK this has nothing to do with sampling with repl

2条回答
  •  忘了有多久
    2021-02-04 08:51

    If your index is unique

    df = df.drop(df_subset.index)
    

    example

    df = pd.DataFrame(np.arange(10).reshape(-1, 2))
    

    sample

    df_subset = df.sample(2)
    df_subset
    


    drop

    df.drop(df_subset.index)
    

提交回复
热议问题