现有一个手机评论数据mobile.csv(1)按手机价格统计评分最大值、最小值、算术平均值和中位数。2)按手机品牌统计评分最大值、最小值、算术平均值和中位数。
时间: 2023-07-10 13:09:53 浏览: 203
首先需要导入 pandas 库,读取 mobile.csv 文件并将数据存储在 DataFrame 中。
```python
import pandas as pd
df = pd.read_csv('mobile.csv', encoding='utf-8')
```
## 按手机价格统计评分
### 最大值
```python
max_score = df.groupby('price')['score'].max()
print(max_score)
```
### 最小值
```python
min_score = df.groupby('price')['score'].min()
print(min_score)
```
### 算术平均值
```python
mean_score = df.groupby('price')['score'].mean()
print(mean_score)
```
### 中位数
```python
median_score = df.groupby('price')['score'].median()
print(median_score)
```
## 按手机品牌统计评分
### 最大值
```python
max_score = df.groupby('brand')['score'].max()
print(max_score)
```
### 最小值
```python
min_score = df.groupby('brand')['score'].min()
print(min_score)
```
### 算术平均值
```python
mean_score = df.groupby('brand')['score'].mean()
print(mean_score)
```
### 中位数
```python
median_score = df.groupby('brand')['score'].median()
print(median_score)
```
阅读全文