Recommand · May 14, 2022 0


How do I calculate the percentage (counted non-numerical values) in Pandas?

Basically, I have the columns date and intensity which I have grouped by date this way:

intensity = dataframe_scraped.groupby(["date","intensity"]).count()['sentiment'] which yielded the following results:

date     intensity      
2021-01  negative           33
         neutral            72
         positive           44
         strong_negative    24
         strong_positive    22
                            ..
2022-05  positive           13
         strong_negative    20
         strong_positive    16
         weak_negative      12
         weak_positive      18

I want to calculate the percentages of these numerical values by date in order to bar-plot it later. Any ideas on how to achieve this?

I’ve tried something na├»ve along the lines of: 100 * dataframe_scraped.groupby(["date","intensity"]).count()['sentiment'] / dataframe_scraped.groupby(["date","intensity"]).count()['sentiment'].transform('sum')




You may also like…




amazon-web-services android angular api arrays c# css dart dataframe django docker excel express firebase flutter html ios java javascript jquery json kotlin laravel linux list mongodb mysql node.js pandas php postgresql python python-3.x r react-native reactjs regex spring spring-boot sql sql-server string swift typescript vue.js