How to return the Index when slicing Pandas Dataframe
<pre><code> df2=   pd.DataFrame(df1.iloc[:, [n for n in random.sample(range(1, 7), 3)]])
</code></pre>

<blockquote>
  <p>returns df1 rows and selected columns but it returns a generic index 0,1,2,3..etc instead
  of   returning       the Datetime index of df1 which is what I want to keep. I tried:</p>
</blockquote>

<pre><code>df2=df1.copy(deep=True)

df2= pd.DataFrame(data=None, columns=df1.columns, index=df1.index)
df2= df1.iloc[:, [n for n in random.sample(range(1, 7), 3)]]
</code></pre>

<p>but it does not work... </p>

<p>what about slightly different approach?</p>

<pre><code>In [66]: df
Out[66]:
            c1  c2  c3
2016-01-01   4   0   3
2016-01-02   2   3   2
2016-01-03   1   2   3
2016-01-04   3   3   0
2016-01-05   1   0   4
2016-01-06   1   1   1
2016-01-07   2   3   3
2016-01-08   2   2   2
2016-01-09   4   0   0
2016-01-10   1   1   0
2016-01-11   1   3   0
2016-01-12   4   3   1
2016-01-13   0   0   3
2016-01-14   3   1   0
2016-01-15   4   3   1

In [67]: rnd = df.sample(n=6)

In [68]: rnd.index
Out[68]: DatetimeIndex(['2016-01-04', '2016-01-03', '2016-01-12', '2016-01-02', '2016-01-01', '2016-01-13'], dtype='datetime64[ns]', freq=None)

In [69]: rnd
Out[69]:
            c1  c2  c3
2016-01-04   3   3   0
2016-01-03   1   2   3
2016-01-12   4   3   1
2016-01-02   2   3   2
2016-01-01   4   0   3
2016-01-13   0   0   3
</code></pre>

python pandas indexing dataframe slice