Pandas df 'inndata' with weekly interval data:
Date | Item | X | Y | Z |
---|---|---|---|---|
12-21-2021 | aa | -100 | 50 | -50 |
bb | 100 | 100 | 200 | |
cc | 300 | -50 | 250 | |
12-28-2021 | aa | 75 | -50 | 25 |
bb | -75 | -50 | -125 | |
cc | 50 | 100 | 150 | |
... | ... | ... | ... | ... |
12-20-2022 | aa | 200 | 55 | 255 |
bb | -25 | -50 | -75 | |
cc | -100 | 100 | 0 |
Using pandas, how do I select rows at chosen intervals, for example 1 week and/or 1 year, while leaving out others, and report the data from column Z, for a result resembling the following table with historical data going back in time?
Item | 1W | 1YR |
---|---|---|
aa | -50 | 255 |
bb | 200 | -75 |
cc | 250 | 0 |
Unsuccessful attempt:
inndata['Z'] = pd.DataFrame({
'1W': df.iloc[0,:]
,'1YR': df.iloc[-52,:]
}).T