停车场数据分析:时间分布、高峰时段、收入统计
import numpy as np import matplotlib.pyplot as plt
停车时间的分布情况
def parking_time_distribution(parking_times): plt.hist(parking_times, bins=10) plt.xlabel('Parking Time (minutes)') plt.ylabel('Frequency') plt.title('Parking Time Distribution') plt.show()
停车高峰的时间统计
def peak_time_statistics(entrance_times): hours = [int(time.split(':')[0]) for time in entrance_times] hourly_counts, _ = np.histogram(hours, bins=24, range=(0, 24))
plt.bar(range(24), hourly_counts)
plt.xlabel('Hour')
plt.ylabel('Number of Cars')
plt.title('Peak Time Statistics')
plt.show()
每周繁忙的比例
def weekly_busyness_ratio(entrance_times): weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] daily_counts = np.zeros(7) for time in entrance_times: day = time.split(',')[0] daily_counts[weekdays.index(day)] += 1
plt.pie(daily_counts, labels=weekdays, autopct='%1.1f%%')
plt.title('Weekly Busyness Ratio')
plt.show()
月收入分析
def monthly_revenue_analysis(revenue_data): months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] monthly_revenue = np.zeros(12) for data in revenue_data: month = data[0].split('-')[1] monthly_revenue[months.index(month)] += data[1]
plt.plot(range(1, 13), monthly_revenue)
plt.xlabel('Month')
plt.ylabel('Revenue')
plt.title('Monthly Revenue Analysis')
plt.show()
每日接待车辆的统计
def daily_car_count(entrance_times): daily_counts = np.zeros(31) for time in entrance_times: day = int(time.split(',')[1].split('-')[0]) daily_counts[day-1] += 1
plt.bar(range(1, 32), daily_counts)
plt.xlabel('Day')
plt.ylabel('Number of Cars')
plt.title('Daily Car Count')
plt.show()
示例数据
parking_times = np.random.randint(30, 180, 1000) entrance_times = ['Monday, 01-01-2022 08:30', 'Monday, 01-01-2022 12:15', 'Tuesday, 01-02-2022 09:45', 'Wednesday, 01-03-2022 17:30', 'Thursday, 01-04-2022 10:00'] revenue_data = [('2022-01-01', 500), ('2022-02-01', 800), ('2022-02-15', 1000), ('2022-03-01', 1200), ('2022-05-01', 900)]
调用函数进行分析
parking_time_distribution(parking_times) peak_time_statistics(entrance_times) weekly_busyness_ratio(entrance_times) monthly_revenue_analysis(revenue_data) daily_car_count(entrance_times)
原文地址: https://www.cveoy.top/t/topic/qFzl 著作权归作者所有。请勿转载和采集!