#câu 1
data(iris)
result <- aggregate(
Sepal.Width ~ Species,
data = iris,
FUN = function(x) c(
Min = min(x),
Max = max(x),
SD = sd(x)
)
)
result
## Species Sepal.Width.Min Sepal.Width.Max Sepal.Width.SD
## 1 setosa 2.3000000 4.4000000 0.3790644
## 2 versicolor 2.0000000 3.4000000 0.3137983
## 3 virginica 2.2000000 3.8000000 0.3224966
library(ggplot2)
ggplot(data = iris, aes(x = Species, y = Sepal.Length)) +
geom_boxplot(fill = "lightblue") +
labs(
title = "Boxplot Sepal.Length theo Species",
x = "Species",
y = "Sepal.Length"
) +
theme_minimal()

import pandas as pd
# Đọc file iris.csv (nếu bạn có file thực tế)
# df = pd.read_csv('iris.csv')
# Nếu không có file, dùng dữ liệu Iris chuẩn có sẵn trong nhiều thư viện
# Ở đây tôi dùng cách tải trực tiếp từ nguồn uy tín để đảm bảo đúng dữ liệu
url = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"
df = pd.read_csv(url)
# Hiển thị vài dòng đầu (tùy chọn)
print(df.head())
## sepal_length sepal_width petal_length petal_width species
## 0 5.1 3.5 1.4 0.2 setosa
## 1 4.9 3.0 1.4 0.2 setosa
## 2 4.7 3.2 1.3 0.2 setosa
## 3 4.6 3.1 1.5 0.2 setosa
## 4 5.0 3.6 1.4 0.2 setosa
# Lọc các dòng mà Petal.Length > 4.0
filtered_df = df[df['petal_length'] > 4.0] # Lưu ý: tên cột trong file chuẩn là lowercase
# Đếm số lượng dòng thỏa mãn
count = len(filtered_df)
print(f"Số lượng dòng mà Petal.Length > 4.0: {count}")
## Số lượng dòng mà Petal.Length > 4.0: 84
# Xuất kết quả ra file csv mới
filtered_df.to_csv('count_filtered_petal_length.csv', index=False)
print("Đã xuất file 'count_filtered_petal_length.csv' thành công!")
## Đã xuất file 'count_filtered_petal_length.csv' thành công!