豆瓣TOP250可视化分析Python代码
时间: 2023-06-18 08:04:50 浏览: 155
抱歉,我无法直接提供Python代码。以下是一个豆瓣TOP250电影数据可视化分析的Python代码示例,供您参考:
```python
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# 读取数据
data = pd.read_csv('douban_top250.csv')
# 数据清洗
data['year'] = data['year'].apply(lambda x: int(x.split()[0])) # 只保留年份
data['country'] = data['country'].apply(lambda x: x.split('/')[0]) # 只保留第一个国家
data['rating'] = data['rating'].apply(lambda x: float(x)) # 转换评分为float类型
# 数据分析
plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置中文显示
plt.figure(figsize=(12,6))
# 评分分布直方图
plt.subplot(1,2,1)
sns.histplot(data=data, x='rating', binwidth=0.2, kde=True)
plt.xlabel('评分')
plt.ylabel('电影数量')
plt.title('豆瓣TOP250电影评分分布直方图')
# 上映年份分布箱线图
plt.subplot(1,2,2)
sns.boxplot(data=data, x='year')
plt.xlabel('上映年份')
plt.title('豆瓣TOP250电影上映年份分布箱线图')
plt.tight_layout()
plt.show()
```
上述代码使用了pandas、matplotlib和seaborn等Python库,主要实现了对豆瓣TOP250电影数据进行清洗、分析和可视化。具体分析结果包括评分分布直方图和上映年份分布箱线图。
阅读全文
相关推荐

















