Reputation: 27
I'd like to plot the season on the x-axis and the Greens in Regulation % on the y-axis. The plot is incorrectly showing up like this:
How can I get matplotlib to plot the correct y-axis values?
import pandas as pd
from matplotlib import pyplot as plt
pga = pd.read_csv('/Users/dpericks/Desktop/PGA_Data_Historical.csv')
dj = pga[(pga['Player Name'] == 'Dustin Johnson')
& (pga['Variable'] == 'Greens in Regulation Percentage - (%)')]
plt.plot(dj['Season'], dj['Value'])
Upvotes: 0
Views: 161
Reputation: 703
import pandas as pd
from matplotlib import pyplot as plt
pga = pd.read_csv('PGA_Data_Historical.csv')
dj = pga[(pga['Player Name'] == 'Dustin Johnson')
& (pga['Variable'] == 'Greens in Regulation Percentage - (%)')]
dj_numberic_values_ = pd.to_numeric(dj['Value'])
plt.plot(dj['Season'], dj_numberic_values_)
plt.show()
When I debugged your code, I realized that we get string type
variables from dj['Value']
. I had to convert these values to appropriate numerical values so that matplotlib
can work with them. I hope it helps your problem.
Upvotes: 1