'Results from a iteration in a dataframe doesn't give expected result
I have the next code:
for country in list2fix:
f=df.city_name.eq(country)
x=df[f]
y=x[['Lat','Long']]
y.loc[:,'Lat']=np.radians(y.loc[:,'Lat'])
y.loc[:,'Long']=np.radians(y.loc[:,'Long'])
kmeans = KMeans(n_clusters=2, random_state=0).fit(y)
kmeans.cluster_centers_
What i am trying is filter every element in the list2fix=['Italy','Mexico'...] from a dataframe that contain every city of a country, but i don't need all of the countries in a dataframe, just extract a few of them in a list and then apply k-means, but the results doesn't printed. What I got is a message:
/usr/local/lib/python3.7/dist-packages/pandas/core/indexing.py:1773: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead ValueError: could not convert string to float: 'Italy_North'
What I am doing wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
