how to make a slice by week and year in pandas

Solution 1:

You're missing an OR. IIUC, you want data beyond Week 49 of 2021. In logical expression that can be written as the year is greater than 2021 OR the year is 2021, but the week is greater than 49:

out = table[((table.Year == 2021) & (table.Week >= 49)) | (table.Year > 2021)]

Output:

   Year  Week  Sales
2  2021    49      4
3  2021    50      6
4  2021    51      7
5  2021    52     10
6  2022     1      2