无法使用matplotlib绘制数据,MySQL数组中的数字表示为(Decimal('')

时间:2018-11-17 23:08:31

标签: python mysql matplotlib

我正试图散布NFL WR的职业生涯,他们在联赛的前两个赛季加起来都不足1000码。

当我只在Workbench中运行一个表时,所有数据都会显示其外观。但是当我使用下面的代码将其引入PyCharm时,我认为出了点问题。当我plt.show()时,我得到一个带有“图1”的窗口,但是里面没有任何东西。当我打印(TDpG)时,我回来了:

[Decimal('44')Decimal('48')Decimal('33')Decimal('43')Decimal('25')...]

这是我的问题的原因吗?我需要在数据库查询中进行更改吗?

import mysql.connector as con
import matplotlib as mpl

mpl.use('TkAgg')
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

mydb = con.connect(
    host="localhost",
    user="root",
    password="=",
    database="NFLffDB"
)

mycursor = mydb.cursor()

wr = "SELECT (cartdrec/TotalGames) as TDpG, (carecy/TotalGames) as YpG FROM `NFLffDB`.`player`JOIN  ( SELECT offense.player as playerid, sum(offense.trg) as cartrg, sum(offense.rec) as carec, sum(offense.recy) as carecy, sum(offense.tdrec) as cartdrec, count(offense.player) as TotalGames FROM `NFLffDB`.`offense`JOIN  ( SELECT * FROM  ( SELECT player.player as badearlyWR, player.start as Start, player.pname, player.pos1, sum(offense.trg) as trg, sum(offense.rec) as earlyrec, sum(offense.recy) as earlyrecy, sum(offense.tdrec) as earlytdrec FROM `NFLffDB`.`player`JOIN offense on player.player =  offense.player WHERE player.pos1 = 'WR' and offense.year < player.start + 2 and offense.year != 2017  GROUP BY player.player, player.start ) AS subQWR2 WHERE subQWR2.earlyrecy < 1000 ) as youngcareer on offense.player =  youngcareer.badearlyWR WHERE year > Start+1 and year < Start+7             GROUP BY offense.player ) as CarNum on player.player=CarNum.playerid ORDER BY YpG DESC LIMIT 200; "
mycursor.execute(wr)

myresult = mycursor.fetchall()

df = pd.DataFrame(list(myresult), columns=["TDpG", "YpG"])

TDpG = np.array(df.TDpG)
YpG = np.array(df.YpG)

plt.scatter(TDpG, YpG)

plt.show()

0 个答案:

没有答案