#Câu 1:
library(ggplot2)
data(iris)
sep_len_quartiles <- quantile(iris$Sepal.Length)
print("Các tứ phân vị của Sepal.Length:")
## [1] "Các tứ phân vị của Sepal.Length:"
print(sep_len_quartiles)
## 0% 25% 50% 75% 100%
## 4.3 5.1 5.8 6.4 7.9
ggplot(iris, aes(x = Species, y = Petal.Length, fill = Species)) +
geom_boxplot() +
labs(title = "Biểu đồ Boxplot của Petal.Length theo loài",
x = "Loài (Species)",
y = "Độ dài cánh hoa (Petal.Length)") +
theme_minimal()
#Câu 2:
#library(reticulate)
#py_config()
#py_install("pandas")
data(iris)
write.csv(iris, "iris.csv", row.names = FALSE)
import pandas as pd
# Đọc file iris.csv
df = pd.read_csv("iris.csv")
# Nhóm theo Species và tính thống kê Sepal.Width
summary = df.groupby("Species")["Sepal.Width"].agg(
mean="mean",
min="min",
max="max"
)
# Xuất file theo yêu cầu đề
summary.to_csv("species_summary.csv")
summary
## mean min max
## Species
## setosa 3.428 2.3 4.4
## versicolor 2.770 2.0 3.4
## virginica 2.974 2.2 3.8