'''
Description: covid datasets显示
Autor: 365JHWZGo
Date: 2021-11-11 22:15:46
LastEditors: 365JHWZGo
LastEditTime: 2021-11-11 23:35:41
'''
import numpy as np
row_data = [
["Name", "StudentID", "Age", "AttendClass", "Score"],
["小明", 20131, 10, 1, 67],
["小花", 20132, 11, 1, 88],
["小菜", 20133, None, 1, "98"],
["小七", 20134, 8, 1, 110],
["花菜", 20134, 98, 0, None],
["刘欣", 20136, 12, 0, 12]
]
print('原始数据:\n',row_data)
data1 = np.array(row_data)
print('预处理的数据:\n',data1)
data_process = []
for i in range(len(row_data)):
if i == 0:
continue
data_process.append(row_data[i][1:])
data = np.array(data_process, dtype=np.float)
print('需要处理的部分数据:\n',data)
sid = data[:, 0]
unique, counts = np.unique(sid, return_counts=True)
data[4, 0] = 20135
normal_age_mask = ~np.isnan(data[:,1]) & (data[:,1] < 20)
normal_age_mean = data[normal_age_mask, 1].mean()
data[~normal_age_mask, 1] = normal_age_mean
data[data[:,2] == 0, 3] = np.nan
data[:, 3] = np.clip(data[:, 3], 0, 100)
afterData = np.array(data1, dtype=object)
for i in range(len(data)):
afterData[i+1][1:] = data[i]
print('清理之后的数据:\n',afterData)
|