A
A
Artem Seleznev2018-11-09 18:42:44
Python
Artem Seleznev, 2018-11-09 18:42:44

How to get index in pandas DataFrame?

There is a DataFrame, I can't get indexes out of it.
Example:

```
                          a   b   c
id              tstamp
0   2016-03-23 12:00:00   0   1   2
     2016-03-23 12:00:00   3   4   5
1   2016-03-23 13:00:00   6   7   8
     2016-03-23 13:00:00   9  10  11
     2016-03-23 14:00:00  12  13  14
2   2016-03-23 14:00:00  15  16  17
3   2016-03-23 15:00:00  18  19  20
   2016-03-23 16:00:00  24  25  26
5  2016-03-23 17:00:00  27  28  29 ```

Need to get:
0 2016-03-23 12:00:00
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2018-11-09
@seleznev_artem_info

https://pandas.pydata.org/pandas-docs/stable/gene...

In [13]: df = pd.DataFrame([{'a': 1, 'b': 2, 'c':3}, {'a':4, 'b':5, 'c':6}])
In [14]: df
Out[14]: 
   a  b  c
0  1  2  3
1  4  5  6
In [15]: df.set_index(['a','b'], inplace=True)
In [16]: df
Out[16]: 
     c
a b   
1 2  3
4 5  6

In [35]: df.index.to_frame().reset_index()
Out[35]: 
   a  b
0  1  2
1  4  5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question