Skip first row in pandas dataframe when creating list
<p>I am currently creating a data frame from a specific column in my csv file. I am then creating a list from the values in the data frame, but I would look to skip over the first element in the data frame and not include it in my list. How can I go about doing that?</p>

<p>Here's the code that i'm using which is functioning:</p>

<pre><code>df = pd.read_csv(filename, header = None, error_bad_lines = False, usecols = [9], names =
['addresses'])
addresses = df['addresses'].tolist()
addresses = [x for x in addresses if str(x) != 'nan']
</code></pre>

<p>I think you can use <code>indexing</code> <code>[1:]</code> - select all values excluding first:</p>

<pre><code>addresses = [x for x in addresses[1:] if str(x) != 'nan']
</code></pre>

<p>Or:</p>

<pre><code>addresses = df.loc[1:, 'addresses'].tolist()
</code></pre>

<p>Sample:</p>

<pre><code>df = pd.DataFrame({'addresses':[4,8,7]})
print (df)
   addresses
0          4
1          8
2          7

addresses = df.loc[1:, 'addresses'].tolist()
print (addresses)
[8, 7]
</code></pre>

<p>Another solution, thanks <a href="http://stackoverflow.com/questions/39559805/skip-first-row-in-pandas-dataframe-when-creating-list/39559825?noredirect=1#comment66430370_39559825">Nickil Maveli</a>:</p>

<pre><code>import pandas as pd
import io

temp=u"""10
20
30
"""
#after testing replace io.StringIO(temp) to filename
df = pd.read_csv(io.StringIO(temp), header=None, skiprows=[0], names=['addresses'])
print (df)
   addresses
0         20
1         30 
</code></pre>

python pandas