câu 1:
# Tính độ lệch chuẩn của Sepal.Length theo từng nhóm Species
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
sd_sepal <-iris %>%
group_by(Species) %>%
summarise(
SD_Sepal_Length = sd(Sepal.Length)
)
sd_sepal
## # A tibble: 3 × 2
## Species SD_Sepal_Length
## <fct> <dbl>
## 1 setosa 0.352
## 2 versicolor 0.516
## 3 virginica 0.636
library(ggplot2)
# Vẽ biểu đồ violin của Petal.Width theo từng nhóm Species bằng ggplot2
ggplot(iris, aes(x = Species, y = Petal.Width, fill = Species)) +
geom_violin(trim = FALSE) +
labs(
title = "Biểu đồ violin của Petal.Width theo Species",
x = "Loài hoa (Species)",
y = "Petal Width"
) +
theme_minimal()

Câu 2:
data(iris)
write.csv(iris, "iris.csv", row.names = FALSE)
import pandas as pd
# Doc file iris.csv
df = pd.read_csv("iris.csv")
# Loc cac dong co Sepal.Width nho hon 3.0
filtered_df = df[df["Sepal.Width"] < 3.0]
print(filtered_df.head())# in 5 dòng đầu tiên của dữ liệu sau khi đã lọc cột Sepal.Width
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 8 4.4 2.9 1.4 0.2 setosa
## 41 4.5 2.3 1.3 0.3 setosa
## 53 5.5 2.3 4.0 1.3 versicolor
## 54 6.5 2.8 4.6 1.5 versicolor
## 55 5.7 2.8 4.5 1.3 versicolor
filtered_df.to_csv("filtered_width.csv", index=False)
print("Da loc va luu file filtered_width.csv")
## Da loc va luu file filtered_width.csv