1

I can't really include the DataFrame (since it is work related). But I have the following. I have a dataframe, with several columns, one of these columns contains 'product codes' and these are unique strings. Now there is also another column with quantities (an integer) of these 'product codes'. I've counted the product codes because I wanted to find out the most popular product code, and naively tried to multiply strings and floats - to which I got an error. << counts = df.Product_Id.value_counts >>. So I guess I want to filter by row or something, but I'm not sure how to do that. My count is a lot smaller than 'quantity' so I can't really multiply it by 'quantity' meaningfully. Can this be done in Pandas or should I use something else?

4

1 回答 1

1

如果您提供一些示例数据会很有帮助,不能太难编造一些东西。

print df

     product  quantity
0  Product A         1
1  Product A         4
2  Product A         3
3  Product A         8
4  Product B         1
5  Product B         2
6  Product B         9
7  Product C         1
8  Product C         2

然后:

df.groupby('product').sum()

           quantity
product            
Product A        16
Product B        12
Product C         3
于 2013-07-24T08:39:54.460 回答