擅长:python、mysql、java
<p>以下面的<code>dataframe</code>为例:</p>
<pre><code>In [2454]: df
Out[2454]:
customer_id
0 1
1 2
2 3
3 4
4 5
5 8
6 9
7 10
</code></pre>
<p>您可以使用<a href="https://www.programiz.com/python-programming/methods/set/symmetric_difference" rel="nofollow noreferrer">^{<cd2>}</a>:</p>
<pre><code>In [2437]: a = df['customer_id'].tolist()
In [2431]: b = [x for x in range(a[0], a[-1] + 1)]
In [2438]: missing_vals = list(set(a) ^ set(b))
In [2439]: missing_vals
Out[2439]: [6, 7]
</code></pre>