为什么我不能用pymatplot绘图在斯派德?

2024-06-16 15:04:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我在上一门在线课程。在练习中,我要绘制两个直方图,比较下雨和不下雨的乘客人数,这是我在在线课程中使用的代码。在

import numpy as np
import pandas
import matplotlib.pyplot as plt

def entries_histogram(turnstile_weather):

    plt.figure()
    ax = turnstile_weather['ENTRIESn_hourly'][turnstile_weather['rain'] == 0].plot(kind = 'hist', title = 'Histogram of ENTRIESn_hourly', bins = 30)
    turnstile_weather['ENTRIESn_hourly'][turnstile_weather['rain'] == 1].plot(kind = 'hist', bins = 30, ax=ax)
    ax.set_ylabel('Frequency')
    ax.set_xlabel('ENTRIESn_hourly')
    return plt

它在在线课程的网页上运行得很完美,但当我安装了Anaconda并使用Spyder软件运行完全相同的代码时。它显示了一个错误:

^{pr2}$

为什么?在


Tags: 代码importplotaspltaxhist课程
1条回答
网友
1楼 · 发布于 2024-06-16 15:04:00

快速解答:您可以通过将pandas更新到最新版本来解决此问题:

conda install pandas

在版本0.15.0中,kind='hist'选项被添加到Series.plot()中。您的代码示例应该适用于最新版本0.15.2

有关更多信息,请参见github上的release notes of 0.15.0和{a2}的增强部分。在

相关问题 更多 >