Issue
I'm starting my first data science project. First step is to plot all shots from the 2018 NHL season. Can't seem to figure out how to make the x and y coordinates pull from xCord and yCord columns both int64 data types.
import pandas as pd
import numpy as py
import matplotlib.pyplot as plt
shots = pd.read_csv('NHL_Project/Data/shots_2007-2020.csv')
shot = shots[['homeTeamCode', 'awayTeamCode', 'season','isPlayoffGame','game_id','homeTeamWon', 'period', 'time','period','team','location','event','goal','xCord','yCord','shotType','playerPositionThatDidEvent','playerNumThatDidEvent','goalieIdForShot','goalieNameForShot','shooterPlayerId','shooterName','shooterLeftRight','shotWasOnGoal']].head()
fig = plt.figure(figsize=(100,100))
ax = plt.axes()
t = py.linspace(-100, 100, 100) # return 100 numbers between -100 and 100
x = ['xCord']
y = ['yCord']
ax.plot(x, y, color='red', marker='D')
Solution
Didn't run this code, cause I don't have your data, but it should work.
You should get the x
and y
from your dataframe, but both of them are set as a list, [xCord']
and [yCord]
.
import pandas as pd
import numpy as py
import matplotlib.pyplot as plt
shots = pd.read_csv('NHL_Project/Data/shots_2007-2020.csv')
shot = shots[['homeTeamCode', 'awayTeamCode', 'season','isPlayoffGame','game_id','homeTeamWon', 'period', 'time','period','team','location','event','goal','xCord','yCord','shotType','playerPositionThatDidEvent','playerNumThatDidEvent','goalieIdForShot','goalieNameForShot','shooterPlayerId','shooterName','shooterLeftRight','shotWasOnGoal']].head()
fig = plt.figure(figsize=(100,100))
ax = plt.axes()
t = py.linspace(-100, 100, 100) # return 100 numbers between -100 and 100
ax.plot(x=shots.xCord, y=shots.yCord, color='red', marker='D')
Answered By - Ali Hejazizo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.