python读取excel速度分析_从excel文件读取数据进行分析

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:19   2315   0

我有下面两个我写的代码和excel文件。我只是不明白如何将它们组合起来,这样我就可以从excel文件中读取并使用这些数字组成一个簇。在import matplotlib.pyplot as plt

import xlrd

from matplotlib import style

style.use("ggplot")

from sklearn.cluster import KMeans

fileWorkspace = 'C://Users/bob/Desktop/'

pull=[]

wb1 = xlrd.open_workbook(fileWorkspace + 'try.xlsx')

sh1 = wb1.sheet_by_index(0)

for a in range(0,sh1.nrows):

for b in range(0,sh1.ncols):

pull.append(sh1.cell(a,b).value)

print('Finished in row' + str(a))

x = [11,19,23,33,44,91,92,90,60,63]

y = [92,85,22,25,86,78,63,51,66,15]

X = [list(item) for item in zip(x,y)]

kmeans = KMeans(n_clusters=3)

kmeans.fit(X)

centroids = kmeans.cluster_centers_

labels = kmeans.labels_

print(centroids)

print(labels)

colors = ["g.","r.","y.","c.","m.","k."]

for i in range(len(X)):

print("coordinate:",X[i], "label:", labels[i])

plt.plot(X[i][0], X[i][1], colors[labels[i]], markersize = 10)

plt.scatter(centroids[:, 0],centroids[:, 1], marker = "x", s=150, linewidths=5, zorder=10)

plt.show()

excel文件图像:

f548817e0081a2ec941fb59a26e93a75.png

这很复杂,因为我必须读取这一行数据,然后进行聚类。而且我必须跳过行和列来阅读它们。在

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP