想跟着别人的代码测试一下KMeans,但是在运行过程中出现
ModuleNotFoundError: No module named 'pandas'
代码
import random
import pandas as pd
import numpy as nm
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn import preprocessing
from sklearn.preprocessing import StandardScaler
from scipy.spatial.distance import cdist # 计算距离
import matplotlib.pyplot as plt # 绘图
def savaData(filePath, data):
'''
用于保存输出结果到指定路径下
:param filePath: 保存结果的目的文件路径
:param data: 结果数据
:return:
'''
file = open(filePath, 'w+', encoding='utf-8') # 注意规定编码格式
file.write(str(data)) # 写入结果数据
file.close()
df = pd.read_excel('task3_1 food1.xlsx');
df1 = df.dropna() # 删除含有数据缺失的行
#print(df1.head()) # 输出表格前5行`
data = df1.drop('食物名', axis=1, inplace=False) # 删除'食物名'列 axis=0代表删除行,1代表删除列 inplace=False代表不改变原表 True代表改变原表
data = data.drop('序号', axis=1, inplace=False) # 删除'序号'列
print(data.head())
#错误
[Running] python -u "d:\Code\python\food.py"
Traceback (most recent call last):
File "d:\Code\python\food.py", line 2, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
[Done] exited with code=1 in 0.084 seconds