У меня есть фрейм данных с 3 столбцами: неделя, месяц и плановые даты, где неделя имеет номер в диапазоне от 1 до 4, Месяц - это список месяцев с января по де c, а Плановые даты - список дат год.
Это выглядит так:
week, month, planneddates
1, [1,2,3], [ ... ]
4, [7,9], [ ...]
Полная выборка данных:
week, month, planneddates
1, ['1', '3', '5', '7', '9', 'nov'], [datetime.date(2019, 4, 1), datetime.date(2019, 4, 8), datetime.date(2019, 4, 15), datetime.date(2019, 4, 22), datetime.date(2019, 4, 29), datetime.date(2019, 5, 6), datetime.date(2019, 5, 13), datetime.date(2019, 5, 20), datetime.date(2019, 5, 27), datetime.date(2019, 6, 3), datetime.date(2019, 6, 10), datetime.date(2019, 6, 17), datetime.date(2019, 6, 24), datetime.date(2019, 7, 1), datetime.date(2019, 7, 8), datetime.date(2019, 7, 15), datetime.date(2019, 7, 22), datetime.date(2019, 7, 29), datetime.date(2019, 8, 5), datetime.date(2019, 8, 12), datetime.date(2019, 8, 19), datetime.date(2019, 8, 26), datetime.date(2019, 9, 2), datetime.date(2019, 9, 9), datetime.date(2019, 9, 16), datetime.date(2019, 9, 23), datetime.date(2019, 9, 30), datetime.date(2019, 10, 7), datetime.date(2019, 10, 14), datetime.date(2019, 10, 21), datetime.date(2019, 10, 28), datetime.date(2019, 11, 4), datetime.date(2019, 11, 11), datetime.date(2019, 11, 18), datetime.date(2019, 11, 25), datetime.date(2019, 12, 2), datetime.date(2019, 12, 9), datetime.date(2019, 12, 16), datetime.date(2019, 12, 23), datetime.date(2019, 12, 30), datetime.date(2020, 1, 6), datetime.date(2020, 1, 13), datetime.date(2020, 1, 20), datetime.date(2020, 1, 27), datetime.date(2020, 2, 3), datetime.date(2020, 2, 10), datetime.date(2020, 2, 17), datetime.date(2020, 2, 24), datetime.date(2020, 3, 2), datetime.date(2020, 3, 9), datetime.date(2020, 3, 16), datetime.date(2020, 3, 23), datetime.date(2020, 3, 30)]
4, ['dec', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'oct', 'nov'], [datetime.date(2019, 4, 1), datetime.date(2019, 4, 8), datetime.date(2019, 4, 15), datetime.date(2019, 4, 22), datetime.date(2019, 4, 29), datetime.date(2019, 5, 6), datetime.date(2019, 5, 13), datetime.date(2019, 5, 20), datetime.date(2019, 5, 27), datetime.date(2019, 6, 3), datetime.date(2019, 6, 10), datetime.date(2019, 6, 17), datetime.date(2019, 6, 24), datetime.date(2019, 7, 1), datetime.date(2019, 7, 8), datetime.date(2019, 7, 15), datetime.date(2019, 7, 22), datetime.date(2019, 7, 29), datetime.date(2019, 8, 5), datetime.date(2019, 8, 12), datetime.date(2019, 8, 19), datetime.date(2019, 8, 26), datetime.date(2019, 9, 2), datetime.date(2019, 9, 9), datetime.date(2019, 9, 16), datetime.date(2019, 9, 23), datetime.date(2019, 9, 30), datetime.date(2019, 10, 7), datetime.date(2019, 10, 14), datetime.date(2019, 10, 21), datetime.date(2019, 10, 28), datetime.date(2019, 11, 4), datetime.date(2019, 11, 11), datetime.date(2019, 11, 18), datetime.date(2019, 11, 25), datetime.date(2019, 12, 2), datetime.date(2019, 12, 9), datetime.date(2019, 12, 16), datetime.date(2019, 12, 23), datetime.date(2019, 12, 30), datetime.date(2020, 1, 6), datetime.date(2020, 1, 13), datetime.date(2020, 1, 20), datetime.date(2020, 1, 27), datetime.date(2020, 2, 3),
datetime.date(2020, 2, 10), datetime.date(2020, 2, 17), datetime.date(2020, 2, 24), datetime.date(2020, 3, 2), datetime.date(2020, 3, 9),
datetime.date(2020, 3, 16), datetime.date(2020, 3, 23), datetime.date(2020, 3, 30)]
Что я хочу сделать, это создать новый столбец из запланированных дат под названием " Новый столбец ".
Новый столбец должен выбирать только те даты, которые соответствуют определенной неделе и месяцу из списка запланированных дат.
Желаемая структура вывода:
week, month, new column
1, [1,2,3], [ filtered ... ]
4, [7,9], [ filtered ... ]
Желаемый вывод, соответствующий выборочным данным:
week, month, new column
1 ['1', '3', '5', '7', '9', 'nov'] [datetime.date(2019, 5, 6), datetime.date(2019, 7, 1), datetime.date(2019, 9, 2), datetime.date(2019, 11, 4), datetime.date(2020, 1, 6), datetime.date(2020, 3, 2)]
4 ['dec', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'oct', 'nov'] [datetime.date(2019, 4, 22), datetime.date(2019, 5, 27), datetime.date(2019, 6, 24), datetime.date(2019, 7, 22), datetime.date(2019, 8, 26), datetime.date(2019, 9, 23), datetime.date(2019, 10, 28), datetime.date(2019, 11, 25) datetime.date(2019, 12, 23), datetime.date(2020, 1, 27), datetime.date(2020, 2, 24), datetime.date(2020, 3, 23)]