What is the fast way to get a list with the corresponding serial number with pandas?
<p>I have to drop some columns, sometimes the columns name is hart to type, so I want to get a list or tuple or array with the corresponding serial number, then I can drop them with <code>df1.drop(df1.columns[[0, 1, 3]], axis=1)</code>.</p>

<p>What is the fast way with pandas to do it like this?</p>

<pre><code>In [2]: df1.columns
Out[2]: Index(['Unnamed: 0', 'Unnamed: 1', 'Unnamed: 2', 'Unnamed: 3', 'ä¸ç­', 'ä¸ç­',
       'ä¸ç­.1', 'ä¸ç­.1', 'Unnamed: 8', 'Unnamed: 9', 'Unnamed: 10',
       'Unnamed: 11'],
        dtype='object'
In [3]: a = df1.columns.tolist()
        b = list(range(len(df1.columns)))
        tuple(zip(a, b))
Out[3]: (('Unnamed: 0', 0),
        ('Unnamed: 1', 1),
        ('Unnamed: 2', 2),
        ('Unnamed: 3', 3),
        ('ä¸ç­', 4),
        ('ä¸ç­', 5),
        ('ä¸ç­.1', 6),
        ('ä¸ç­.1', 7),
        ('Unnamed: 8', 8),
        ('Unnamed: 9', 9),
        ('Unnamed: 10', 10),
        ('Unnamed: 11', 11))
In [4]: df1.drop(df1.columns[6:], axis=1)
</code></pre>

<p>Finally, I found a way to do it fast and easy:</p>

<pre><code>for i, element in enumerate(df.columns):
    print(i, element)
</code></pre>

python pandas