FlashKeepers

Data Science · College · College and University

pandas II: GroupBy, Merge and Reshaping

groupby, agg, merge and join types, concat, pivot, melt, apply, datetime handling and method chaining.

About this set

40 basic cards for College Data Science. Set 2 of 2 in pandas. It opens with "What does groupby() do?" and "What is the basic syntax for groupby in pandas?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What does groupby() do?
Show answerSplits a DataFrame into groups based on one or more columns, allowing separate computation on each group.
What is the basic syntax for groupby in pandas?
Show answerdf.groupby('column_name')
How do you group by multiple columns in pandas?
Show answerdf.groupby(['col1', 'col2'])
What is the difference between size() and count() after groupby?
Show answersize() counts all rows including NaN, count() counts non-null values only.
How do you access a single group by name from a GroupBy object?
Show answergrouped_obj.get_group('group_name')
What does reset_index() do after groupby aggregation?
Show answerConverts the grouped index back to a regular column, flattening the result to a regular DataFrame.
What is the purpose of agg() in pandas?
Show answerApplies one or more aggregation functions to grouped data or a DataFrame.
How do you apply a single aggregation function with agg()?
Show answerdf.groupby('col').agg('sum') or df.groupby('col').agg(np.sum)
How do you apply different functions to different columns with agg()?
Show answerdf.groupby('col').agg({'col1': 'sum', 'col2': 'mean'})
How do you apply multiple aggregation functions to the same column with agg()?
Show answerdf.groupby('col').agg({'col1': ['sum', 'mean', 'std']})
What is the named aggregation syntax in pandas?
Show answerdf.groupby('col').agg(new_col=('old_col', 'sum'))
What does merge() do?
Show answerCombines two DataFrames based on a common column or index, similar to SQL joins.
What is an inner join?
Show answerReturns only rows where the key exists in both DataFrames.
What is a left join?
Show answerReturns all rows from the left DataFrame and matching rows from the right DataFrame.
What is a right join?
Show answerReturns all rows from the right DataFrame and matching rows from the left DataFrame.

25 more cards in the app

Study this set free