Skip to content
Advertisement

Tag: aggregate

Pandas: using groupby to calculate a ratio by specific values

Hi I have a dataframe that looks like this: and I want to calculate a ratio in the column ‘count_number’, based on the values in the column ‘tone’ by this formula: [‘blue’+’grey’]/’red’ per each unite combination of ‘participant_id’, ‘session’, ‘block’ – here is part of my dataset as text, the left column ‘RATIO’ is my expected output: participant_id session block

Aggregate data with two conditions

I have a data frame that looks something like this: What I would like to do is aggregate the data if the dates are the same – but only if the name is different. So the above data frame should actually become: Currently I am almost doing it with: However, this will also aggregate the ones where the name is

How to sort aggregated numpy array?

My first post on stackoverflow + am very new to programming. Apologies in advance for any poor formatting and missing information. :) I aggregated two columns in a csv file (one column of seller names, the other of transactional amounts) to find how much each seller has made in total: I want to sort it in descending order to find

Pandas: groupby followed by aggregate – unexpected behaviour when joining strings

Having a pandas data frame containing two columns of type str: which is created as follows: df = pd.DataFrame({“group”:[1,2,2,1],”sc”:[“A”,”B”,”C”,”D”],”wc”:[“word1”, “word2”, “word3″,”word4”]}) When grouping by group and joining the individual columns, I can use: However, when specifying a single column (wc) to perform this operation on: which appears to be a join on the column names. But why is it handled

PySpark Dataframe melt columns into rows

As the subject describes, I have a PySpark Dataframe that I need to melt three columns into rows. Each column essentially represents a single fact in a category. The ultimate goal is to aggregate the data into a single total per category. There are tens of millions of rows in this dataframe, so I need a way to do the

Advertisement