读取iris数据集中鸢尾花的萼片,花瓣长度,并对其进行排序、去重、并求出和,累计和,均值,标准差、方差、最大值和最小值。用jupyter
时间: 2024-10-16 13:09:37 浏览: 63
在Python中,我们可以使用Pandas库来操作像Iris数据集这样的数据。首先,你需要导入所需的库,如pandas和numpy。假设你已经通过`sklearn.datasets.load_iris()`加载了Iris数据集,并将其存储在一个名为`df`的数据框中。
```python
import pandas as pd
import numpy as np
from sklearn.datasets import load_iris
# 加载 iris 数据集
data = load_iris()
df = pd.DataFrame(data.data, columns=data.feature_names)
# 花瓣和萼片长度
sepal_length = df['sepal length (cm)']
petal_length = df['petal length (cm)']
# 排序、去重、求和、累计和
sepal_length_sorted = sepal_length.sort_values()
sepal_length_unique = sepal_length.drop_duplicates()
sepal_length_sum = sepal_length.sum()
sepal_length_cumulative_sum = sepal_length_sorted.cumsum()
petal_length_sorted = petal_length.sort_values()
petal_length_unique = petal_length.drop_duplicates()
petal_length_sum = petal_length.sum()
petal_length_cumulative_sum = petal_length_sorted.cumsum()
# 计算统计量
sepal_length_mean = sepal_length.mean()
sepal_length_std = sepal_length.std()
sepal_length_var = sepal_length.var()
sepal_length_max = sepal_length.max()
sepal_length_min = sepal_length.min()
petal_length_mean = petal_length.mean()
petal_length_std = petal_length.std()
petal_length_var = petal_length.var()
petal_length_max = petal_length.max()
petal_length_min = petal_length.min()
阅读全文