我遇到unhashable type: 'numpy.ndarray'
错误。因此我将df_subset
,'Views'
投射到int
,但是它返回了object
这是脚本:
tsne = TSNE(n_components=2, verbose=1, perplexity=20, n_iter=1000)
tsne_results = tsne.fit_transform(logits_list)
df_subset = pd.DataFrame({'X':tsne_results[:,0], 'Y':tsne_results[:,1], 'Views':targets})
print(df_subset)
df_subset.astype({'Views': 'int'}).dtypes
print(df_subset.dtypes)
colors = {'A2CH':'red', 'A3CH':'green', 'A4CH_LV':'blue', 'A4CH_RV':'cyan', 'A5CH':'magneta', 'Apical_MV_LA_IAS':'yellow',
'PLAX_TV':'black', 'PLAX_full':'white', 'PLAX_valves':'orange', 'PSAX_AV':'purple', 'PSAX_LV':'dodgerblue', 'Subcostal_IVC':'lightgreen', 'Subcostal_heart':'darkcyan', 'Suprasternal':'grey'}
ax = sns.scatterplot(x= "X", y= "Y", hue='Views', legend = 'full',palette = colors, data=df_subset)
plt.show()
这是df_subset and dtype
的印刷品:
X Y Views
0 13.208739 -19.657906 [11]
1 7.932375 -31.547863 [6]
2 -3.896450 -23.075047 [9]
3 -11.836237 -12.138339 [9]
4 -8.077571 17.220371 [11]
5 9.463497 23.756912 [2]
6 8.354083 -47.790867 [10]
7 -2.848731 -0.220144 [9]
8 25.724466 -29.862696 [9]
9 -26.956612 -8.361418 [9]
10 -16.011475 2.309184 [7]
11 16.193329 -0.280985 [8]
12 5.060284 -9.906323 [9]
13 37.827713 -16.174528 [4]
14 -5.971475 -39.845860 [7]
15 6.608039 9.085782 [12]
16 -20.108206 -26.253906 [8]
17 32.851559 0.332044 [2]
18 23.818949 13.762548 [2]
19 23.625357 -12.107020 [3]
X float32
Y float32
Views object
dtype: object
我假设由于对象类型而收到unhashable type: 'numpy.ndarray'
错误?任何帮助,将不胜感激。
答案 0 :(得分:1)
.astype()
返回一个副本,因此可以复制
df_subset = df_subset.astype({'Views': int})