python 3.x - Pandas: How do I get the key (index) of the first and last row of a dataframe -


i have dataframe (df) datetime index , 1 field "myfield"

i want find out first , last datetime of dataframe.

i can access first , last dataframe element this:

df.iloc[0] df.iloc[-1] 

for df.iloc[0] result:

myfield myfieldcontent

name: 2017-07-24 00:00:00, dtype: float

how can access datetime of row?

you can use select index [0] or [-1]:

df = pd.dataframe({'myfield':[1,4,5]}, index=pd.date_range('2015-01-01', periods=3)) print (df)             myfield 2015-01-01        1 2015-01-02        4 2015-01-03        5  print (df.iloc[-1]) myfield    5 name: 2015-01-03 00:00:00, dtype: int64  print (df.index[0]) 2015-01-01 00:00:00  print (df.index[-1]) 2015-01-03 00:00:00 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -