How to lag data by x specific days on a multi index pandas dataframe?
问题 I have a dataframe that has dates, assets, and then price/volume data. I'm trying to pull in data from 7 days ago, but the issue is that I can't use shift() because my table has missing dates in it. date cusip price price_7daysago 1/1/2017 a 1 1/1/2017 b 2 1/2/2017 a 1.2 1/2/2017 b 2.3 1/8/2017 a 1.1 1 1/8/2017 b 2.2 2 I've tried creating a lambda function to try to use loc and timedelta to create this shifting, but I was only able to output empty numpy arrays: def row_delta(x, df, days,