##Câu 1: Dùng R để Tính trung bình, phương sai và độ lệch chuẩn của Sepal.Width cho tất cả dòng dữ liệu Vẽ biểu đồ scatter giữa Petal.Length và Petal.Width, phân loại theo Species bằng ggplot2
library(ggplot2)
# Load dữ liệu iris (có sẵn trong R)
data <- iris
# Caculate mea, variance, standard deviation
mean_sepal_width <- mean(iris$Sepal.Width)
var_sepal_width <- var(iris$Sepal.Width)
sd_sepal_width <- sd(iris$Sepal.Width)
mean_sepal_width
## [1] 3.057333
var_sepal_width
## [1] 0.1899794
sd_sepal_width
## [1] 0.4358663
ggplot(iris, aes(x = Petal.Length, y = Petal.Width, color = Species)) +
geom_point(size = 2.5) +
labs(
title = "Scatter plot giữa Petal.Length và Petal.Width",
x = "Petal Length",
y = "Petal Width"
) +
theme_minimal()
##Câu 2: Đọc file iris.csv Tính tổng giá trị của Sepal.Length và Sepal.Width theo từng loại Species Xuất kết quả ra file total_by_species.csv
import pandas as pd
data = pd.read_csv("iris.csv")
print(data)
## 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
## .. ... ... ... ... ...
## 145 6.7 3.0 5.2 2.3 Virginica
## 146 6.3 2.5 5.0 1.9 Virginica
## 147 6.5 3.0 5.2 2.0 Virginica
## 148 6.2 3.4 5.4 2.3 Virginica
## 149 5.9 3.0 5.1 1.8 Virginica
##
## [150 rows x 5 columns]
total_result = data.groupby("species")[["sepal.length", "sepal.width"]].sum()
# Xuất ra file total_by_species.csv
total_result.to_csv("total_by_species.csv")
print(total_result)
## sepal.length sepal.width
## species
## Setosa 250.3 171.4
## Versicolor 296.8 138.5
## Virginica 329.4 148.7