擅长:python、mysql、java
<p>使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.duplicated.html" rel="nofollow noreferrer">^{<cd1>}</a>+<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.astype.html" rel="nofollow noreferrer">^{<cd2>}</a>掩码<code>int</code>:</p>
<pre><code>print (df.duplicated())
0 False
1 True
2 True
3 False
4 True
5 False
6 True
dtype: bool
df['ColumnB'] = df.duplicated().astype(int)
print (df)
ColumnA ColumnB
0 A 0
1 A 1
2 A 1
3 B 0
4 B 1
5 C 0
6 C 1
</code></pre>