Search code examples
pythonpandasindexingperiod

How to call out daily value through period index


I have a dataframe using periodindex (daily) starting from 1992-01-03.

I am trying to call out the data using period index, like dataframe['1992-01-03'], but it returned an error message--Key Error:'1992-01-03'. However, it works well if I call out by year or month, e.g., dataframe['1992'], or dataframe['1992-01'].

I can call out the daily value by using dataframe.loc['1992-01-03'].

Can anyone briefly explain why this is happening?


Solution

  • Without .loc

    dataframe['1992-01-03']
    

    Is check the column

    With .loc is search the index

    dataframe.loc['1992-01-03']