答案
This commit is contained in:
1 parent
ae0d509dbd
commit
029237b364
12 files changed
+1055
-116
No files matched your search
@@ -1 +1,36 @@
|
||||
import pandas as pd
|
||||
import pandas as pd
|
||||
from pathlib import Path
|
||||
|
||||
# 第1关:认识岩性识别数据
|
||||
# 请补全下列代码,完成数据读取、字段查看和岩性类别统计。
|
||||
|
||||
# 1. 读取数据
|
||||
# 提示:数据文件路径为 /data/workspace/lithology/lithology.csv
|
||||
SRCPATH = Path("/data/workspace/lithology/lithology.csv")
|
||||
if not SRCPATH.exists():
|
||||
SRCPATH = Path("lithology.csv") # pyright: ignore[reportConstantRedefinition]
|
||||
|
||||
df = pd.read_csv(SRCPATH)
|
||||
|
||||
# 2. 定义输入特征列
|
||||
# 提示:岩性识别的输入特征包括 AC、CAL、GR、K、RD、SP
|
||||
feature_cols = ['AC', 'CAL', 'GR', 'K', 'RD', 'SP']
|
||||
|
||||
# 3. 定义标签列
|
||||
# 提示:岩性类别标签列为 Lithology
|
||||
label_col = 'Lithology'
|
||||
|
||||
# 4. 输出数据的行数和列数
|
||||
print("数据形状:", df.shape)
|
||||
|
||||
# 5. 输出所有字段名称
|
||||
print("字段名称:", list(df.columns))
|
||||
|
||||
# 6. 统计每一类岩性的样本数量
|
||||
lithology_counts = df[label_col].value_counts().sort_index()
|
||||
print("岩性类别统计:")
|
||||
print(lithology_counts)
|
||||
|
||||
# 7. 输出输入特征列表和标签名称
|
||||
print("输入特征:", feature_cols)
|
||||
print("标签名称:", label_col)
|
||||
Reference in new issue
Block a user