(1)用pandas库读取tmdb 5000 movies.csv文件,查看前3行、后2行。 (2)选择列 Budget, ld、 original language、 release date, popularty, fifte, 用pandaspopularity.csv。 据预处理模块将缺失值丢弃处理,并导出到新的 (v 文作 Bodn smo le f Bointe (3)利用pandas库重新读取新的数据集 mdb_5000 movies budgt popularty.csv,并选择字段original_language——"en”的所有数据集,导出为文本文件 tmdtb 5000 movies balgt popularity_en.txt,要求数据之间用逗号分隔,每行末尾包含换行符。 (4)读取文本文件 tmdb_5000 _movies_budgt popularity en.txt 并转存到 Excel 文件mdb_5000_movies_budgt_popularity_en.xlsx中。 (5)重新读取文本文件读取文本文件 tmdb_5000_ movies budgt popularity_en.txt,首先按照电影 title升序排序,分别可视化显示2000~2010年发行电影的 Budget. popularity的值,要求每幅图均包括图例、图标题,x轴刻度值为电影title且斜45°显示(为了显示美观,可以将电影title每隔若干个抽样显示),每幅图曲线颜色分别为红色、绿色;每幅图分别保存为png图片保存,分辨率为400 dpi,png图片命名分别为 movies_en_budget2000_2010.png、movies_en_popularity_2000_2010.png。
时间: 2024-03-02 07:51:33 浏览: 121
很抱歉,作为AI语言模型,我无法为您执行本地文件操作,但我可以给您提供相应的代码:
(1) 读取文件并查看前3行、后2行
```python
import pandas as pd
df = pd.read_csv('tmdb_5000_movies.csv')
print(df.head(3))
print(df.tail(2))
```
(2) 选择需要的列,处理缺失值并导出为新文件
```python
df = pd.read_csv('tmdb_5000_movies.csv', usecols=['budget', 'id', 'original_language', 'release_date', 'popularity', 'vote_count'])
df.dropna(inplace=True)
df.to_csv('tmdb_5000_movies_budget_popularity.csv', index=False)
```
(3) 选择"original_language"为"en"的数据集并导出为文本文件
```python
df = pd.read_csv('tmdb_5000_movies_budget_popularity.csv')
df_en = df[df['original_language']=='en']
df_en.to_csv('tmdb_5000_movies_budget_popularity_en.txt', index=False, sep=',', line_terminator='\n')
```
(4) 读取文本文件并转存为Excel文件
```python
df = pd.read_csv('tmdb_5000_movies_budget_popularity_en.txt', sep=',')
df.to_excel('tmdb_5000_movies_budget_popularity_en.xlsx', index=False)
```
(5) 按照要求分别绘制两幅图并保存为png文件
```python
import matplotlib.pyplot as plt
# 提取2000-2010年的数据
df_year = df[df['release_date'].str[:4].astype(int).between(2000, 2010)]
# 绘制budget图
df_budget = df_year.sort_values(by='budget')
fig, ax = plt.subplots(figsize=(15,8))
ax.plot(df_budget['id'], df_budget['budget'], 'r-')
ax.set_xticklabels(df_budget['title'][::20], rotation=45)
ax.set_xlabel('Movie Title')
ax.set_ylabel('Budget')
ax.set_title('Movies Released from 2000 to 2010 - Budget')
ax.legend()
plt.savefig('movies_en_budget2000_2010.png', dpi=400)
# 绘制popularity图
df_popularity = df_year.sort_values(by='popularity')
fig, ax = plt.subplots(figsize=(15,8))
ax.plot(df_popularity['id'], df_popularity['popularity'], 'g-')
ax.set_xticklabels(df_popularity['title'][::20], rotation=45)
ax.set_xlabel('Movie Title')
ax.set_ylabel('Popularity')
ax.set_title('Movies Released from 2000 to 2010 - Popularity')
ax.legend()
plt.savefig('movies_en_popularity_2000_2010.png', dpi=400)
```
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20250102104920.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)