How to Access Pandas dataframe columns when the number of columns are unknown before hand
<p>I am new to python and data science altogether.  I am writing a program to read and analyze a csv with pandas. The problem is that the csv will be supplied by the user and it can have variable number of columns depending on the user.  I do  not have a prior knowledge of the column names.
I went about the problem by reading the csv using pandas and read the column names into a python list. However problem ensued when I attempted to access the dataframe column by supplying the indexed list as a column name. something like this:</p>

<pre><code>#List of column names, coln
coln = df.columns
df.ix[:, df.coln[0]] # to access the first column of the dataframe.
</code></pre>

<p>But this did not work. Please help how do I do this? PLEASE HELP!</p>

<p>You can use <code>iloc</code></p>

<pre><code>df.iloc[:,0]
</code></pre>

<p>Btw, <code>df.coln</code> does not exist you created <code>coln</code> as separate variable. </p>

python pandas data-science