Finding label location in a DataFrame Index

后端 未结 3 1783
傲寒
傲寒 2020-11-29 04:55

I have a pandas dataframe:

import pandas as pnd
d = pnd.Timestamp(\'2013-01-01 16:00\')
dates = pnd.bdate_range(start=d, end = d+pnd.DateOffset(days=10), nor         


        
3条回答
  •  离开以前
    2020-11-29 05:22

    Get dataframe integer index given a date key:

    >>> import pandas as pd
    
    >>> df = pd.DataFrame(
        index=pd.date_range(pd.datetime(2008,1,1), pd.datetime(2008,1,5)),
        columns=("foo", "bar"))
    
    >>> df["foo"] = [10,20,40,15,10]
    
    >>> df["bar"] = [100,200,40,-50,-38]
    
    >>> df
                foo  bar
    2008-01-01   10  100
    2008-01-02   20  200
    2008-01-03   40   40
    2008-01-04   15  -50
    2008-01-05   10  -38
    
    >>> df.index.get_loc(df["bar"].argmax())
    1
    
    >>> df.index.get_loc(df["foo"].argmax())
    2
    

    In column bar, the index of the maximum value is 1

    In column foo, the index of the maximum value is 2

    http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.get_loc.html

提交回复
热议问题