## Ex 5-1. QPushButton.
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
#
#
# class MyApp(QWidget):
#
# def init(self):
# super().__init__()
# self.initUI()
#
# def initUI(self):
# btn1 = QPushButton('&Button1', self)
# btn1.setCheckable(True)
# btn1.toggle()
#
# self.btn2 = QPushButton(self)
# self.btn2.setText('Button')
# self.btn2.clicked.connect(self.clickBtnPrint)
#
# btn3 = QPushButton('Button3', self)
# btn3.setEnabled(False)
#
# vbox = QVBoxLayout()
# vbox.addWidget(btn1)
# vbox.addWidget(self.btn2)
# vbox.addWidget(btn3)
#
# self.setLayout(vbox)
# self.setWindowTitle('QPushButton')
# self.setGeometry(300, 300, 300, 200)
# self.show()
#
# def clickBtnPrint(self):
# print('Hello')
# if self.btn2.text() == 'Button':
# self.btn2.setText('Hello World')
#
#
# if name == '__main__':
# app = QApplication(sys.argv)
# ex = MyApp()
# sys.exit(app.exec_())
# import pandas as pd
# data = pd.read_csv('data.csv')
#
# print(data)
import csv
import matplotlib.pyplot as plt
import numpy as np
f = open('data2.csv', 'r', encoding='ansi')
rdr = csv.reader(f)
db = []
for line in rdr:
print(line)
db.append(line)
f.close()
for i in range(len(db)):
for j in range(len(db[i])):
if i>=2 and j>=2:
db[i][j] = float(db[i][j])
print(db[i][j], end=' ')
print()
xData = []
yData = []
getcha = [] # 70
# 최고 검거율의 범죄와 최저 검거율의 범죄를 출력하는 프로그램을 추가하세요
min = 101
minName = 0 # 0, '', None
max = -1
maxName = 0
getcha2 = []
for i in range(2, len(db)):
yData.append(db[i][2])
xData.append(db[i][3])
print(db[i][0] + '_' + db[i][1], db[i][3] / db[i][2] *100, '%')
getcha.append(db[i][0] + '_' + db[i][1])
getcha2.append(db[i][3] / db[i][2] *100)
for i in range(len(getcha2)):
if min > getcha2[i]:
min = getcha2[i]
minName = getcha[i]
print(minName, min)
for i in range(len(getcha2)):
if max < getcha2[i]:
max = getcha2[i]
maxName = getcha[i]
print('>',maxName, max)
print('최고 검거율의 범죄는', maxName, '검거율은', max, '%')
print(xData, yData)
y = db[2][2]
x = db[2][3]
print('검거율:', x/y*100)
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1)
years = [getcha]
values = [yData]
plt.bar(x, values)
plt.xticks(x, years)
plt.savefig('savefig_default.png')
plt.show()
# for i in range(1, len(db)):
# for j in range(1, len(db[i])):
# db[i][j] = int(db[i][j])
# print(db)
#
# for i in range(1, len(db)):
# plt.plot(db[i][1:])
#
# plt.show()