擅长:python、mysql、java
<p>可以使用<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.r_.html" rel="noreferrer">^{<cd1>}</a>无缝组合多个范围/切片:</p>
<pre><code>from string import ascii_uppercase
df = pd.DataFrame(columns=list(ascii_uppercase))
idx = np.r_[3:10, -5:0]
print(idx)
array([ 3, 4, 5, 6, 7, 8, 9, -5, -4, -3, -2, -1])
</code></pre>
<p>然后可以使用<code>idx</code>为列编制索引并馈送到<a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html" rel="noreferrer">^{<cd3>}</a>:</p>
<pre><code>df.drop(df.columns[idx], axis=1, inplace=True)
print(df.columns)
Index(['A', 'B', 'C', 'K', 'L', 'M', 'N',
'O','P', 'Q', 'R', 'S', 'T', 'U'], dtype='object')
</code></pre>