inputs=inputs.fillna(inputs.mean(numeric_only=True))
print(inputs)
这样就能解决
1 Like
小白来交作业
def drop_NaN_most(data):
count = 0
count_max = 0
labels = data.columns
for label in labels:
count = data[label].isna().sum()
if count > count_max:
count_max = count
flag = label
return data.drop(flag, axis=1)
new_data = drop_NaN_most(data)
inputs, outputs = new_data.iloc[:, 0], new_data.iloc[:, 1]
inputs = inputs.fillna(inputs.mean(numeric_only=True))
import torch
X, y = torch.tensor(inputs.values), torch.tensor(outputs.values)
print(X, y)
Submit my work
import os
import pandas as pd
import torch
os.makedirs(os.path.join('..', 'data'), exist_ok=True)
file_path = os.path.join('..', 'data', 'score.csv')
with open(file_path, 'w') as f:
f.write('name,pol,eng,math,408\n')
f.write('mtj,72,54,98,109\n')
f.write('mwj,78,68,100,106\n')
f.write('lbh,NA,NA,NA,NA\n')
f.write('rx,66,NA,NA,NA\n')
data = pd.read_csv(file_path)
print(data)
outputs = data.iloc[:, 1:5]
outputs = outputs.fillna(outputs.mean())
print(outputs)
x = torch.tensor(outputs.values)
print(x)
1 Like