Convert Pandas Dataframe Date Index and Column to Numpy Array
<p>How can I convert 1 column and the index of a Pandas dataframe with several columns to a Numpy array with the dates lining up with the correct column value from the dataframe?</p>

<p>There are a few issues here with data type and its driving my nuts trying to get both the index and the column out and into the one array!!</p>

<p>Help would be much appreciated!</p>

<p>IIUC you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.values.html" rel="nofollow"><code>values</code></a>:</p>

<pre><code>start = pd.to_datetime('2015-02-24')
rng = pd.date_range(start, periods=5)

df = pd.DataFrame({'a': range(5), 'b':list('ABCDE')}, index=rng)  
print (df)
            a  b
2015-02-24  0  A
2015-02-25  1  B
2015-02-26  2  C
2015-02-27  3  D
2015-02-28  4  E

print (df.values)
[[0 'A']
 [1 'B']
 [2 'C']
 [3 'D']
 [4 'E']]
</code></pre>

<p>if need index values also first convert <code>datetime</code> to <code>string</code> values in <code>index</code> and then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow"><code>reset_index</code></a> for converting <code>index</code> to column:</p>

<pre><code>df.index = df.index.astype(str)
print (df.reset_index().values)
[['2015-02-24' 0 'A']
 ['2015-02-25' 1 'B']
 ['2015-02-26' 2 'C']
 ['2015-02-27' 3 'D']
 ['2015-02-28' 4 'E']]
</code></pre>

python arrays pandas numpy dataframe