-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_usrpic.py
More file actions
42 lines (35 loc) · 1.12 KB
/
load_usrpic.py
File metadata and controls
42 lines (35 loc) · 1.12 KB
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
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="719458145",
database="bank_index",
auth_plugin='mysql_native_password'
)
def usr_info(prod):
mycursor = mydb.cursor()
sql = "select avg(Invest_amount),avg(Overdue_rate),avg(Age),avg(Degree) from Usr_info as t1, Prod_data as t2 where t1.Usr_ID=t2.Usr_ID and Prod=" + "'" + prod + "'"
mycursor.execute(sql)
data = mycursor.fetchall()
# print(data)
jsonData = []
for row in data:
result = {}
result['trd'] = round(row[0],2)
result['overdue'] = round(row[1], 2) # 平均违约率
result['age'] = round(row[2]) # 平均投资额
dgr = round(row[3])
if dgr==0:
result['degree'] = '高中及以下'
elif dgr==1:
result['degree'] = '大专'
elif dgr == 2:
result['degree'] = '本科'
elif dgr == 3:
result['degree'] = '硕士'
else:
result['degree'] = '博士及以上'
jsonData.append(result)
print(jsonData)
return jsonData
# usr_info('A')