My data has columns:
| Area_code | ProductID | Stock
Date ----------------------------------
2016-04-01 | 920 | 100000135 2.000
2016-05-01 | 920 | 100000135 4.125
2016-06-01 | 920 | 100000135 7.375
2016-07-01 | 920 | 100000135 7.000
2016-08-01 | 920 | 100000135 4.500
2016-09-01 | 920 | 100000135 2.000
2016-10-01 | 920 | 100000135 6.175
2016-11-01 | 920 | 100000135 4.750
2016-12-01 | 920 | 100000135 2.625
2017-01-01 | 920 | 100000135 1.625
2017-02-01 | 920 | 100000135 4.500
2017-03-01 | 920 | 100000135 4.625
2017-04-01 | 920 | 100000135 1.000
2016-04-01 | 920 | 100000136 0.100
2016-06-01 | 920 | 100000136 0.075
2016-07-01 | 920 | 100000136 0.200
2016-09-01 | 920 | 100000136 0.100
2017-03-01 | 920 | 100000136 0.050
2017-05-01 | 920 | 100000136 0.100
2017-06-01 | 920 | 100000136 0.025
2018-05-01 | 920 | 100000136 0.125
2018-08-01 | 920 | 100000136 0.200
2018-12-01 | 920 | 100000136 0.050
2019-02-01 | 920 | 100000136 0.100
2019-03-01 | 920 | 100000136 0.050
The data is present in Pandas dataframe with index "Date" column. The requirement is to iterate over this dataframe, and brings only those rows in another dataframe(inside a loop), that has same "Area_Code" and "Product_ID", to get the result as:
(Say, in iteration 1 of loop, for (920, 100000135) pair), the dataframe in loop should return:
Stock
Date -----
2016-04-01 | 2.000
2016-05-01 | 4.125
.
.
.
2017-04-01 | 1.000
(Then, in iteration 2 of loop, for (920, 100000136) pair), the dataframe in loop should return:
Stock
Date -----
2016-04-01 | 0.100
2016-06-01 | 0.075
.
.
.
2019-03-01 | 0.050
Also, If my dataframe generated above [i.e. as a result of (Area_code, ProductID) pair] has number of records less than 12, I want to skip that iteration and return me the values next iteration.
Please help on this requirement. Kindly mention if anything is unclear in question. Many thanks.