def K_meanAnalyze(self,H1bInfo):
#Get the states values
worksites = H1bInfo['WORKSITE']
H1City, H1State = worksites.str.split(', ', 1)
#Reading Latitude and Longitude data (taking out null)
H1LatLong = H1bInfo.loc[H1State != 'NA']
H1LatLong = H1LatLong[['lon','lat']]
H1LatLong = H1LatLong.dropna()
H1Long = H1LatLong['lon'].values
H1Lat = H1LatLong['lat'].values
#K-Means clustering to see where the applicants were
nClusters = 10
kmeans = KMeans(n_clusters=nClusters, random_state=0).fit(H1LatLong.values)
#Getting the cluster for each case
kl = kmeans.labels_
H1LatLong['Cluster'] = kl
H1LatLong['State'] = H1State
H1LatLong = H1LatLong.dropna()
return H1LatLong
if __name__ == "__main__":
h1bSystem = H1bInfo()
try:
H1Info = pd.read_csv('h1b_history.csv')
except IOError:
print("Error: cannot find the path,pleas put data and program in the same folder")
else:
print("data file read successfully")
function = 1
k_meanResult = h1bSystem.K_meanAnalyze(H1Info)
I am working in google colab, I wrote this code and although I defined the function, I get the following error. I looked at the site but I couldn't find a similar error. How to solve it?
AttributeError Traceback (most recent call last)
<ipython-input-114-f029a4ae230e> in <cell line: 1>()
10
11 function = 1
---> 12 k_meanResult = h1bSystem.K_meanAnalyze(H1Info)
13
14 salary_Result = h1bSystem.salaryAnalyze(H1Info, k_meanResult)
AttributeError: 'H1bInfo' object has no attribute 'K_meanAnalyze