Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

How to Apply different aggregations for different columns

$
0
0

@niranjan_283 wrote:

I want to different type of aggregations to by columns after grouping based on Certain Columns. i was able to achieve that using the

tempstatecity = customerdata.groupby(["Last_state","Last_city"]) 
tempstatecity["Customer_ID","Buy_Times","Customer_Value"].agg({"CountOfCustomer":"count","AvgCountOfPurchases":"avg","AvgOfPurchaseValue":"avg"})

but the use of .agg function depreciated recently, how to do different aggregations for different columns?

Recently i have found a way of aggregation but it won’t help me in applying different aggregations for different columns.

tempstatecity = customerdata.groupby(["Last_state","Last_city"])
tempstatecity[["Customer_ID","Buy_Times","Customer_Value"]].agg(["count","sum"])

Output will be like:
image

But i want to apply different aggregations like count for customer_id and sum for Buy_Times etc…,Any help in achieving this would be very helpful

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles