我将缺失数据填补之后生成的新数据怎么保存成csv?运行结果可以看到,但是导出成csv出了问题
看了网上的教学,但是却出现了以下提示:
'numpy.ndarray' object has no attribute 'to_csv'
######这是我的代码
#导入数据
file_path=r"D:\data211130.csv"
import pandas as pd
df=pd.read_csv(file_path)
print(df)
#方法
from sklearn.impute import KNNImputer
KI = KNNImputer(n_neighbors=5, weights="uniform")
#训练数据、转换数据
df_transformed=KI.fit_transform(df)
print(df_transformed)
#导出csv
df_transformed.to_csv(r" C:\Users\11512\Desktop\KNN211201.csv",index=False)
运行结果及报错内容
File "C:\Users\11512\Desktop\1130.py", line 19, in <module>
df_transformed.to_csv(r" C:\Users\11512\Desktop\KNN211201.csv",index=False)
AttributeError: 'numpy.ndarray' object has no attribute 'to_csv'