zhanghaitao1
5/30/2019 - 4:38 PM

month end with trading date

    @staticmethod
    def convert_monthly(df,date_field,endswith='trade_dt'):
        ds = df[date_field].unique()
        if endswith=='trade_dt':
            tds = pd.Series(ds, ds).resample('M').last().values
        else:
            tds=pd.Series(ds,ds).resample('M').last().index.tolist()
        df = df[df['con_date'].isin(tds)]
        return df