I have a dataframe called 'data' that I want to group by and sum based off of multiple keys:
NAME ORDER COST
Joe Burger 10
Joe Burger 12
Jill Fries 5
Joe Nachos 8
I run
data = data.groupby(['NAME','ORDER'])['COST'].sum()
and get this:
NAME ORDER COST
Joe Burger 22
Nachos 8
Jill Fries 5
but I am losing they key 'Joe' for the second row. I want the dataframe to keep all keys so that if Joe has multiple burger orders, it will be prefaced with Joe all the way down like so:
NAME ORDER COST
Joe Burger 22
Joe Nachos 8
Jill Fries 5
Similar dataframe initialization: df = pd.DataFrame({'NAME': ['Joe', 'Jill', 'Joe', 'Joe'], 'ORDER': ['burger', 'fries', 'burger', ' Ube'], 'COST': [1, 2, 3, 6]})