-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_complaints_count.py
45 lines (38 loc) · 1.34 KB
/
product_complaints_count.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 26 15:49:44 2018
@author: vicky
"""
import pandas as pd
import csv
import matplotlib.pyplot as plt
from matplotlib import style
import numpy as np
#from numpy import genfromtxt
style.use('ggplot')
with open('Consumer_Complaints.csv','r') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader)
product_list = []
product_complaint_count = dict()
for line in csv_reader:
if line[1] not in product_list:
product_list.append(line[1])
product_complaint_count[line[1]]=product_complaint_count.get(line[1],0)+1
# print(product_list)
# print(product_complaint_count)
with open('Product_Complaint.csv','w') as new_file:
csv_writer = csv.writer(new_file)
csv_writer.writerow(['product','Complaint_Count'])
for key,value in product_complaint_count.items():
csv_writer.writerow([key,value])
plt.bar(range(len(product_complaint_count)),product_complaint_count.values(),align='center')
plt.xticks(range(len(product_complaint_count)),list(product_complaint_count.keys()))
plt.title('Product vs Number of Complaints Analysis')
plt.xlabel('Complaint Against Product')
plt.ylabel('Counts of Complaint')
plt.legend()
fig = plt.gcf()
plt.show()
fig.savefig('Product_vs_complaintCount')