Sum of Multiple Columns in Interactive Dashboard (Streamlit)

Viewed 14

I am trying to create an interactive dashboard using Streamlit. I have a pandas dataframe as below:

 Name  Region  2017  2018  2019
 a     e       3     3     1    
 b     f       4     5     2    
 c     e       3     6     3   
 d     f       3     7     1    

Essentially, what I want to do group the name by region, and then return the sum by year to plot a bar chart. However, since it is an interactive dashboard, the user should be able to choose the filters. For example, when the user chooses the region 'e' and the years '2018-2019', the result should show:

 Name  Region 2017  2018  2019
 a     e      3     3     1   
 c     e      3     6     3 

and the sum on the bar chart should be 13. I know how to do the first part by df.query() and .groupby().sum(), but I am not sure how to link that to the second part, which is calculating the sum.

Any help would be much appreciated.

0 Answers
Related