擅长:python、mysql、java
<p>问题是<code>$</code>字符串不是被解释为值,而是被解释为字符串(这行看起来很直,不是吗?)。如果将其转换为(<a href="https://stackoverflow.com/questions/32464280/converting-currency-with-to-numbers-in-python-pandas">as here</a>),则会得到以下结果:</p>
<p><a href="https://i.stack.imgur.com/cjhNV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cjhNV.png" alt="enter image description here"/></a></p>
<pre><code>df = pd.read_csv('https://raw.githubusercontent.com/ObiP1/The-Future-Value-of-Homes/master/AverageHomeValues.csv')
df[df.columns[1:]] = df[df.columns[1:]].replace('[\$,]', '', regex=True).astype(float)
plt.title('Median Cost Of Maryland Homes', fontsize=30)
plt.ylabel('Median Price Of Home',fontsize=25)
plt.yticks(np.arange(0,450001,50000))
plt.xlabel('Year', fontsize=25)
plt.plot(df.YEAR, df.MED_COST, 'o')
plt.grid(True)
</code></pre>