如何用 pandas 选择重复的行? [英] How to select duplicate rows with pandas?

查看:60
本文介绍了如何用 pandas 选择重复的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的数据框:

I have a dataframe like this:

import pandas as pd
dic = {'A':[100,200,250,300],
       'B':['ci','ci','po','pa'],
       'C':['s','t','p','w']}
df = pd.DataFrame(dic)

我的目标是将行分为2个数据框:

My goal is to separate the row in 2 dataframes:

  • df1 =包含沿 B 列(不重复的行)不重复值的所有行.
  • df2 =仅包含重复主题的行.
  • df1 = contains all the rows that do not repeat values along column B (unque rows).
  • df2 = containts only the rows who repeat themeselves.

结果应如下所示:

df1 =      A  B C         df2 =     A  B C
      0  250 po p               0  100 ci s 
      1  300 pa w               1  250 ci t

注意:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆