Question
KeyError('%s not in index' % objarr[mask]) when trying to apply kmeans to data from excel spreadsheet? Code text (in Python): import pandas as pd from
KeyError('%s not in index' % objarr[mask]) when trying to apply kmeans to data from excel spreadsheet? Code text (in Python):
import pandas as pd from scipy import stats from sklearn.cluster import KMeans import matplotlib.pyplot as plt import seaborn as sns
df = pd.read_excel('/Users/Cassady/Dropbox/ThePrimer/soccer_stats.xlsx',sep=';')
#Make a copy of DF df_tr = df
#Transsform the timeOfDay to dummies ##df_tr = pd.get_dummies(df_tr, columns=['timeOfDay'])
#Standardize clmns = ['Sum of Goals', 'Sum of Direct Free kicks','sum_blocked shots', 'sum_successful long'] df_tr_std = stats.zscore(df_tr[clmns])
#Cluster the data kmeans = KMeans(n_clusters=2, random_state=0).fit(df_tr_std) labels = kmeans.labels_
#Glue back to originaal data df_tr['clusters'] = labels
#Add the column into our list clmns.extend(['clusters'])
#Lets analyze the clusters print (df_tr[clmns].groupby(['clusters']).mean())
error text:
Traceback (most recent call last): File "/Users/Cassady/Kmeans own data.py", line 17, in
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started