Skip to content
Advertisement

Tag: group-by

How to vectorize groupby and apply in pandas?

I’m trying to calculate (x-x.mean()) / (x.std +0.01) on several columns of a dataframe based on groups. My original dataframe is very large. Although I’ve splitted the original file into several chunks and I’m using multiprocessing to run the script on each chunk of the file, but still every chunk of the dataframe is very large and this process never

Group dates into list based on value

I have a json object that I’m trying to group item together in. this code returns values grouped by date as the key and then a list of teams and dates like this However, I need it to return and key value pair like this where all the dates for a specific team are in a list as the value

How can I pivot a dataframe?

What is pivot? How do I pivot? Long format to wide format? I’ve seen a lot of questions that ask about pivot tables, even if they don’t know it. It is virtually impossible to write a canonical question and answer that encompasses all aspects of pivoting… But I’m going to give it a go. The problem with existing questions and

Iterating through pandas groupby groups

I have a pandas dataframe school_df that looks like this: Each row represents one project by that school. I’d like to add two columns: for each unique school_id, a count of how many projects were posted before that date and a count of how many projects were completed before that date. The code below works, but I have ~300,000 unique

Advertisement