Find how many times a string appeared (result) in a Pandas dataframe

Viewed 60

I have two logs. One is about actions and their results. Another is about actions and their predicted results. I store them as pandas dataframe. An example of the created data frame is below. The created data frame is same for both.

        actions                       results
0       clean           success_for_assigned_objects
1       blind_dash                 success
2       pick                       success
3       sequential                 failure
4       clean                      timeout
..      ...                        ...                          
92      pick                       failure     
93      clean                      success
94      blind_dash           success_for_objects
95      sequential                 success

I want to create a barplot that compares for each action the percentage of its actual results (comes from df_real results) viz-a-viz percentage of predicted results (comes from df_pred).

The action names can be different in some logs, it won't always be [clean, blind_dash, pick, sequential]. The result status would always be one of the four shown in the example.

The barplot should show for each action the percentage of time there was a success/failure/timeout and compare it with the same in df_predicted.

I think a solution could be to get a dict from the df_pred and df_real respectively that has for each action (key) a list (as value) with the percentages of the four possible results. But perhaps there is a more elegant as in this solution the values would need to manually be appended to a title when plotting. Also if we ever increase the number of results, it would be hard to scale. But I am open to your advice.

0 Answers
Related