I'm importing the following .xlsx file into a dataframe.
dfMenu = pd.read_excel("/Users/FoodTrucks.xlsx")
| Price | Quantity | FoodTruck | FoodTruck_ID |
|---|---|---|---|
| 3.00 | 10 | Burgers | 1 |
| 1.20 | 50 | Tacos | 2 |
| 0.60 | 30 | Tacos | 2 |
| 1.12 | 40 | Drinks | 4 |
| 2.00 | 20 | Burgers | 1 |
My goal is to show the total revenue for each food truck with its ID and name in a new column, called "Revenue".
I am currently trying to use the code below, but I'm struggling with the multiplication of the columns "Price" and "Quantity" into a new one and grouping "FoodTruck" and "FoodTruck_ID" in an elegant way.
df = df.groupby((['FoodTruck', 'FoodTruck_ID'])(df['Revenue'] = df['Price'] * q9['Quantity']))
I am getting a syntax error "SyntaxError: cannot assign to subscript here. Maybe you meant '==' instead of '='?"
What would be the most elegant way to solve it?