Remove non-business days rows from pandas dataframe

前端 未结 4 1386
一向
一向 2020-12-10 10:36

I have a dataframe with second timeseries data of wheat in df.

df = wt[\"WHEAT_USD\"]

2016-05-02 02:00:00+02:00    4.780
2016-05-02 02:01:00+02         


        
4条回答
  •  攒了一身酷
    2020-12-10 11:36

    I am building a backtester for stock/FX trading and I also have these issue with days that are nan because that they are holidays or other non trading days.. you can download a financial calendar for the days that there is no trading and then you need to think about timezone and weekends.. etc..

    But the best solution is not to use date/time as the index for the candles or price. So do not connect your price data to a date/time but just to a counter of candles or prices .. you can use a second index for this.. so for calculations of MA or other technical lines dont use date/time .. if you look at Metatrader 4/5 it also doesnt use date/time but the index of the data is the candle number !!

    I think that you need to let go of the date-time for the price if you work with stock or FX data , of cause you can put them in a column of the data-frame but dont use it as the index This way you can avoid many problems

提交回复
热议问题