Create new column by selecting dataframe subset based on current row value and sum another column
Lets say we have a sample dataframe that looks like this # Create a sample dataframe df = pd.DataFrame({‘num_posts’: [4, 6, 3, 9, 1, 14, 2, 5, 7, 2,12], ‘date’ : [‘2020-03-01’, ‘2020-01-02’, ‘2020-01-03’, ‘2020-01-04’, ‘2019-01-05’, ‘2019-01-06’, ‘2020-01-07’, ‘2020-01-08’, ‘2020-01-09’, ‘2020-01-10′,’2020-01-11’]}) cols=[‘num_posts’] Now i need to create features such as sum(num_posts) for last week of… Read More Create new column by selecting dataframe subset based on current row value and sum another column