Skip to content
Advertisement

Grouping python dataframe by multiple column name

My goal in to split python dataframe by multiple columns. In the case of one column, data frame can be splitted by column ‘X1’ as below, using the groupby method. However, how to split dataframe according to columns X1 and X2?

JavaScript

Advertisement

Answer

If pass another column name is necessary select dfs by tuples:

JavaScript

If want select by strings is possible use join in dict comprehension:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement