Counting number of unresolved tickets per department (using Pandas)

:point_right: 1. The challenge - Use Matplotlib/Seaborn to illustrate a live count of unresolved tickets per department (most likely on Flask)

:bulb: 2. Code

# Library Imports
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

url = "https://mycompany.freshdesk.com/api/v2/tickets?per_page=100"

payload = {}

# API Request
response = requests.request("GET", url, headers=headers, data=payload)
parsed = json.loads(response.content)
# Create Pandas DataFrame
tkts = pd.DataFrame(parsed)

# Ticket Type Represents Which Department Ticket Was Directed To
ticket_for = tkts['type']

# Using str.replace to remove 'Query' and 'Support' from ticket type field
ticket_for = ticket_for.str.replace(' Query', '')
ticket_for = ticket_for.str.replace(' Support', '')

# Tickets Source ('department' field is nested within 'custom_fields')
ticket_from = tkts['custom_fields'].str.get('department')

# Count the number of rows for each value in ticket_for
ticket_for_counts = ticket_for.value_counts()

# Tickets Source ('department' field is nested within 'custom_fields')
ticket_from = tkts['custom_fields'].str.get('department')

# Count the number of rows for each value in ticket_from
ticket_from_counts = ticket_from.value_counts()

# Create a 1x2 grid for subplots
fig, axes = plt.subplots(1, 2, figsize=(12, 5))

# Bar Plot for ticket_for_counts
sns.barplot(x=ticket_for_counts.index, y=ticket_for_counts.values, ax=axes[0])
axes[0].set_title('How Many Unresolved Tickets Per Department')

#rotate x-axis for first barchart labels
axes[0].set_xticklabels(axes[0].get_xticklabels(), rotation=40, horizontalalignment='right')

# Bar Plot for ticket_from_counts
sns.barplot(x=ticket_from_counts.index, y=ticket_from_counts.values, ax=axes[1])
axes[1].set_title('Who Is Logging Those Tickets')

#rotate x-axis for first barchart labels
axes[1].set_xticklabels(axes[1].get_xticklabels(), rotation=40, horizontalalignment='right')

# Show the plots
plt.show()

:camera_flash: 3. Screenshots -

WhoLoggedTickets

Hi all,

First post here so if I fall foul of any rules then let me know and happy to correct the post.

I am trying to get an accurate count of how many unresolved tickets each department has however the count is significantly off. The IT Department currently has 35 while purchasing only has 3. If I try use the documenation’s suggestion of using https://domain.freshdesk.com/api/v2/search/tickets?query="status:2%20OR%20status:3%20OR%20status:6%20OR%20status:7" for the URL (which is supposed to return all unresolved tickets), I do not get any results.

I suspect I am not far off getting this right so if anyone who dabbles in Python knows how to help me get this over the line, I would be very appreciative.
Thanks,
Paul

Hey @hc_pc,

Welcome to The Freshworks Developer Community! :tada:

To help you answer this query, I’ve raised a support ticket on your behalf.