bI_jOdev
bI_jOdev

Reputation: 47

Plot a column data based on setting conditions on other columns

enter image description here

The row consist of around 6000 line items. I am trying to display the bar chart based on a certain condition. I am trying to categorize the Application data using the [Severity,Immediate_Action,Response_code] this will provide me the important data which I visualize it. When the condition is matched. I would like to plot the Application column in a form of bar chart either in x or y-axis.

So far I have to set a condition but I am not sure how will get the value_counts for each Application based on the below condition.

High_Alert = report[(report['Response_Code'] == 200) & (report['Severity'].isin(['High','Medium'])) & (report['Immediate_Action']== 'None')]

I am not good with pandas still trying to learn, but I wonder if I have to use groupby.

import pandas as pd
report = pd.read_csv('Test-Report.csv')
High_Alert = report[(report['Response_Code'] == 200) & (report['Severity'].isin(['High','Medium'])) & (report['Immediate_Action']== 'None')]
report.groupby['Application']

Not sure how to call the condition in the groupby or if there is any other method to do it. To draw a bar chart with respect to each Application. The given set of applications in the csv are only 7. I am not sure if the value_counts() will work in this.

Upvotes: 1

Views: 4358

Answers (2)

bI_jOdev
bI_jOdev

Reputation: 47

For anyone who need help, it worked as expected. But still I was not able to plot the bar chart as expected. but the code is perfect for filtering purpose.

import seaborn as sns
from matplotlib import pyplot as plt
High_Alert = report[(report['Response_Code'] == 200) & (report['Severity'].isin(['High','Medium'])) & (report['Immediate_Action']== 'None')].groupby('Application')['Num._of_Events'].sum().sort_values()
ax = High_Alert.plot(x='list of applications', y='Num. of Events', kind='bar',figsize=(6,6))
ax.set_xlabel('List of Appliations')
ax.set_ylabel('Num of Events')
ax.set_xticklabels(ax.get_xticklabels(),rotation=40,ha='right')

Upvotes: 0

Aniket Dixit
Aniket Dixit

Reputation: 150

You can use seaborn library

import pandas as pd

import seaborn as sns

report = pd.read_csv('Test-Report.csv') 

High_Alert = report[(report['Response_Code'] == 200) & (report['Severity'].isin(['High','Medium'])) & (report['Immediate_Action']== 'None')]

report = pd.read_csv('Test-Report.csv')

sns.countplot('Application',data=High_Alert) #here you can also use hue like hue = 'Severity'

Upvotes: 2

Related Questions