笔记

使用 check_image_validity 方法检查图像的有效性,并统计无效图像的比例和原因。

示例:检查单张图像的有效性

cleaner = DataCleaner()
result = cleaner.check_image_validity("test.jpg")
print("图像检查结果:", result)

批量检查图像有效性

image_paths = ["image1.jpg", "image2.jpg", "image3.jpg"]
invalid_images = []
for path in image_paths:
result = cleaner.check_image_validity(path)
if not result["is_valid"]:
invalid_images.append((path, result["error_message"]))

print("无效图像列表:", invalid_images)
输出示例:

图像检查结果: {'is_valid': True, 'error_message': ''}
无效图像列表: [('image2.jpg', '图像尺寸过小'), ('image3.jpg', '图像可能全黑或全白')]
分析:

通过检查图像有效性,发现部分图像尺寸过小或全黑/全白。

可以进一步统计无效图像的比例,决定是否删除或修复。

表格数据概览

使用Pandas的 describe() 和 info() 方法查看表格数据的基本信息。

示例:查看表格数据的基本信息

data = {
'A': [1, 2, None, 4],
'B': [None, 2, 3, 4],
'value': [1, 2, 100, 3, 4, 5]
}
df = pd.DataFrame(data)

查看描述统计

print("描述统计:\n", df.describe())

查看字段信息和缺失值

print("\n字段信息:\n")
df.info()
输出示例:

描述统计:
A B value
count 3.0 3.0 6.0
mean 2.333333 3.0 19.0
std 1.527525 1.0 43.108
min 1.0 2.0 1.0
25% 1.5 2.5 2.25
50% 2.0 3.0 3.5
75% 3.0 3.5 4.75
max 4.0 4.0 100.0

字段信息:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4 entries, 0 to 3
Data columns (total 3 columns):

Column Non-Null Count Dtype


0 A 3 non-null float64
1 B 3 non-null float64
2 value 4 non-null int64
dtypes: float64(2), int64(1)
memory usage: 224.0 bytes
分析:

字段 A 和 B 存在缺失值。

字段 value 存在异常值(最大值为100,明显偏离其他值)。

posted @ 2026-09-21 10:58  111阳  阅读(12)  评论(0)    收藏  举报