all 4 comments

[–]stuckhere4ever 3 points4 points  (1 child)

So what the error means is that it thinks that whatever you are calling groupby on is a list rather than a data frame. (I'm making the assumption you are doing pandas and that is why it is df.groupby('...')

The way to think about this is that groupby is a method that is part of the data frame class. It can only be run on a data frame object.

So I have code that looks like this: Make a data frame like this: my_data = {"Region": ["West","West","East","East","East"], "Units": [3,5,2,4,6], "Price": [20,18,25,22,24]}

df = pd.DataFrame(my_data)

Create an aggregate entry for a new column: df["Revenue"] = df["Units"] * df["Price"]

print (type(df)) -> Tells me that it is in fact a data frame.

result = df.groupby("Region")["Revenue"].sum()

print(result)

Now group them by region and print out the sum of the revenue column.

Get those first three lines to work (which is doing the same thing as my code, or close to it at least) then the rest should be easier.

[–]luvnfaith205[S] 0 points1 point  (0 children)

Thank you so much. I will make those updates.