<p>您可以链接2个条件-通过比较<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.ne.html" rel="nofollow noreferrer">^{<cd2>}</a>和<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.duplicated.html" rel="nofollow noreferrer">^{<cd3>}</a>的反转掩码,选择所有非<code>one</code>值:</p>
<pre><code>df1 = df[df['number'].ne('one') | ~df['type'].duplicated(keep=False)]
print (df1)
col1 col2 col3 col4 col5 type number
1 3 2 6 11 5 A two
2 4 4 0 22 7 C two
3 5 6 11 8 3 D one
5 2 1 6 3 2 B two
6 6 5 7 9 9 E two
</code></pre>
<p>关于有序分类的另一个想法:</p>
<pre><code>cats = pd.unique(['one'] + df['number'].unique().tolist())
df['number'] = pd.Categorical(df['number'], categories=cats, ordered=True)
df2 = df.sort_values('number').drop_duplicates(subset=['type'], keep='last').sort_index()
print (df2)
col1 col2 col3 col4 col5 type number
1 3 2 6 11 5 A two
2 4 4 0 22 7 C two
3 5 6 11 8 3 D one
5 2 1 6 3 2 B two
6 6 5 7 9 9 E two
</code></pre>