Printing Column Names and Values in Dataframe
<p>The end goal of this question is to plot X and Y for a graph using a dataframe. </p>

<p>I have a dataframe like so:</p>

<pre><code>             Open    High     Low   Close     Volume       stock symbol
Date                                                              
2000-10-19    1.37    1.42    1.24    1.35  373590000         AAPL
2000-10-20    1.36    1.46    1.35    1.39  195836200         AAPL
2000-10-23    1.39    1.49    1.39    1.46  129851400         AAPL
2000-10-24    1.48    1.49    1.34    1.35  192711400         AAPL
2000-10-25    1.36    1.37    1.30    1.32  163448600         AAPL
2000-10-26    1.34    1.42    1.25    1.32  178110800         AAPL
2000-10-27    1.35    1.37    1.28    1.33  181242600         AAPL
2000-10-30    1.37    1.42    1.34    1.38  152558000         AAPL
</code></pre>

<p>And I am trying to plot <code>Date</code> vs. <code>Open</code>. I know there is a way to simply plot, but I will be applying this concept to larger dataframes and would like to know how to do it "long-hand".</p>

<p><strong>What I've tried:</strong></p>

<p><code>print(some_DF['Open'])</code></p>

<p>Result: </p>

<pre><code> Date
    2000-10-19      1.37
    2000-10-20      1.36
    2000-10-23      1.39
    2000-10-24      1.48
    2000-10-25      1.36
    2000-10-26      1.34
</code></pre>

<p><strong>Problem:</strong> </p>

<p>Date seems to be my index, but the column header 'Open' Does not appear.</p>

<p><strong>Question:</strong></p>

<p>How do i print the above Dataframe while having <code>'Open'</code> as my header. Then making some value <code>x</code>=<code>Date</code>'s column and some value <code>y</code> = <code>'Open</code>'s values?</p>

<p><strong>"Expected Code to work":</strong></p>

<p>Im thinking something like</p>

<pre><code>print([some_DF['Open'] headers = 'date','open')
x = some_DF['Date'] #So that this becomes first column of dataframe
y = some_DF['Open'] #So that this becomes second column of dataframe
</code></pre>

<p>You can <code>reset_index</code> on the data-frame and then print the subset dataframe consisting of the two columns</p>

<pre><code>&gt;&gt;&gt; df
            a  b
Date            
2000-10-19  1  3
2000-10-20  2  4
2000-10-21  3  5
2000-10-22  4  6
2000-10-23  5  7
&gt;&gt;&gt; print(df.reset_index()[['Date', 'a']])
        Date  a
0 2000-10-19  1
1 2000-10-20  2
2 2000-10-21  3
3 2000-10-22  4
4 2000-10-23  5
</code></pre>

<p>Like IanS mentioned, you shouldn't worry about how the output looks in pandas. Date was an index and Open a column. The difference in the print statement illustrates that distinction.</p>

<p>Edit:</p>

<p>The <code>df[[list_of_column_names]]</code> is the same as <code>df.loc[:, [list_of_column_names]]</code>. It gives a list of columns to subset the original dataframe.</p>

python python-3.x pandas dataframe