Python停车数据分析代码
时间: 2023-07-10 19:04:14 浏览: 47
以下是一个简单的 Python 停车数据分析代码,可用于处理和分析停车场数据:
```python
import pandas as pd
import matplotlib.pyplot as plt
# 读取停车数据
df = pd.read_csv('parking_data.csv')
# 查看数据
print(df.head())
# 统计每小时停车数量
hourly_counts = df.groupby(df['time'].dt.hour).size()
# 绘制每小时停车数量柱状图
hourly_counts.plot(kind='bar', title='Hourly Parking Counts')
# 统计每天停车数量
daily_counts = df.groupby(df['time'].dt.date).size()
# 绘制每天停车数量折线图
daily_counts.plot(title='Daily Parking Counts')
# 统计每月停车数量
monthly_counts = df.groupby(df['time'].dt.month).size()
# 绘制每月停车数量柱状图
monthly_counts.plot(kind='bar', title='Monthly Parking Counts')
# 显示图形
plt.show()
```
在上面的代码中,我们首先使用 Pandas 库读取停车数据,然后使用 groupby 函数按小时、天和月统计停车数量。接下来,我们使用 Matplotlib 库绘制柱状图和折线图,以可视化停车数据。最后,我们调用 show 函数显示图形。
请注意,上述代码仅为示例代码,您需要根据您的数据格式和分析需求进行修改。