pythonpandasdataframedatetimeindex

Do I have to sort dates chronologically to use pandas.DataFrame.ewm?


I need to calculate EMA for a set of data from csv file where dates are in descending order.

When I apply pandas.DataFrame.ewm I get EMA for the latest (by date) equal to the value. This is because ewm starts observation from top to bottom in DataFrame.

So far, I could not find option to make it reverse for ewm. So I guess, I will have to reverse all my dataset.

Maybe somebody knows how to make ewm start from bottom values? Or is it recommended to always use datetimeindex sorted chronologically? From oldest values on top to newest on the bottom?


Solution

  • From pandas' documentation:

    Times corresponding to the observations. Must be monotonically increasing and datetime64[ns] dtype.

    I guess, datetimeindex must be chronological..