python - Pandas: selecting multiple groups for inset plot -


i have group data frame (grouped_df) used plotting in following way:

grouped_df[['col1','col2','col3']].sum().plot(kind='bar') 

resulting in expected plot, contains group-wise sum 3 columns. however, of groups these sums small compared rest , hence not easy display in same bar plot (see image below).

i want have inset plot these groups. trying,

grouped_df[['col1','col2','col3']].sum() < "cut-off" 

returns boolean "list" of these groups cannot use further slicing/selection subset of groups of data frame.

of course, generate 2 lists of groups , loop through grouped_df not think bright solution problem.

example

for clarity , consistence provide sample data frame grouped grpcol:

grpcol    col1     col2     col3     comment                   0.0505   0.0134   0.0534   foo b         0.0505   0.0134   0.2034   bar         0.0505   0.0134   0.0134   bar c         0.0505   0.0134   0.0331   none d         0.0505   0.0134   0.0342   foo e         0.0505   0.0134   0.2134   baz f         0.0505   0.0134   0.0302   baz d         0.0302   0.0134   0.2134   foo d         0.0204   0.0134   0.0400   foo g         0.0505   0.0134   0.2200   foo h         0.0505   0.0134   0.1734   none h         0.0505   0.0134   0.0073   none 

is looking for?

def apply_cut_off(x1,x2,x3, cut_off):      if x1 < cut_off: return false     elif x2 < cut_off: return false     elif x3 < cut_off: return false     return true  grouped_sum = grouped_df[['col1','col2','col3']].sum()   cutoff_df = grouped_sum[ grouped_sum.apply(lambda x: apply_cut_off(x['col1'], x['col2'], x['col3'], your_cut_off), axis=1)] 

this return data frame columns @ least 1 element below cutoff , can whatever want it.

maybe didn't requirement


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -