根据你提供的代码,我发现在函数sjfb中计算停车时间分布的部分有误,需要进行修改。具体修改如下:

def sjfb(pi_table):
    # 图表标题
    plt.title("停车时间分布图")
    
    # 设置x轴信息
    labels_x = ['1小时', '2小时', '3-5小时', '6-10小时', '11-12小时', '12小时以上']
    
    # 获取表中数据判断车辆停车时间
    df1 = pi_table.loc[(pi_table['price'] <= 3)]
    # 停车1小时及以下
    
    df2 = pi_table.loc[(pi_table['price'] > 3) & (pi_table['price'] <= 6)]
    # 停车2小时及以下
    
    df3 = pi_table.loc[(pi_table['price'] > 6) & (pi_table['price'] <= 15)]
    # 停车3-5小时
    
    df4 = pi_table.loc[(pi_table['price'] > 15) & (pi_table['price'] <= 30)]
    # 停车6-10小时
    
    df5 = pi_table.loc[(pi_table['price'] > 30) & (pi_table['price'] <= 36)]
    # 停车11-12小时
    
    df6 = pi_table.loc[(pi_table['price'] > 36)]
    # 停车12小时以上
    
    # 停车各时间段停车数量
    y = [len(df1), len(df2), len(df3), len(df4), len(df5), len(df6)]
    
    plt.bar(labels_x, y)  # 绘制条形图
    
    # 为每一个图形加数值标签
    for x, y in enumerate(y):
        plt.text(x, y + 30, str(y) + '台', ha='center')
    
    plt.show()  # 显示条形图窗体

需要注意的是,我修改了对停车时间的判断条件,使得每个时间段都能正确分类。

# 智能停车场数据分析import pandas as pdexcelFile=r停车场信息表xlsx#读取文件内容pi_table = pdread_excelexcelFilesheet_name=datapi_table## 12确定停车时间# 引入模块import datetime# 返回星期几标记0代表星期一1代表星期二。。6代表星期天def get_week_numbberdate

原文地址: http://www.cveoy.top/t/topic/i5vT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录