For context, I am trying to measure using regression whether the presence of a competitor ad in a given week affects the metrics of an ad. I am not sure how to consolidate the weeks , or assign Boolean values (1 or 0) based on the presence of a brand during a week, but on a different row.
import pandas as pd
df = pd.DataFrame({'week': ['2019-11-11', '2019-11-11', '2019-11-18', '2019-11-25', '2019-11-11', '2019-11-18', '2019-11-11'],
'brand':['X', 'X-2', 'X', 'X', 'Y', 'Y', 'Z'],
'score': [.34, .25, .54, .23, .22, .34, .44]})
Desired result:
df = pd.DataFrame({'week': ['2019-11-11', '2019-11-11', '2019-11-18', '2019-11-25', '2019-11-11', '2019-11-18', '2019-11-11'],
'brand':['X', 'X-2', 'X', 'X', 'Y', 'Y', 'Z'],
'score': [.34, .25, .54, .23, .22, .34, .44],
'presence_dummy_Y': [1, 1, 1, 0, 1, 1, 1],
'presence_dummy_Z': [1, 1, 0, 0, 1, 0, 1]})