【发布时间】:2021-04-06 22:48:37
【问题描述】:
我的问题类似于这个问题How to solve the AttributeError:'list' object has no attribute 'astype'? 但是,我正在尝试创建一系列字符串,以便在图中绘制。
feature_names = df.iloc[:,maxIndex].columns
newMaxName.append(feature_names)
newMaxName = np.array(newMaxName, dtype =np.str)
newMaxName
所以它给了我输出
array(['shar', 'dec', 'intel', 'like', 'amb', 'met', 'pid', 'prob_o', 'pf_o_sin','pf_o_att','pf_o_sha','pf_o_fun','age_o', 'pf_o_amb'、'pf_o_int'、'attr_o'、'attr'、'attr2_1'、'sinc'、 'shar1_1'、'shar_o'、'amb_o'、'intel1_1'、'attr1_1'、'fun_o']、 dtype='
我希望它们是字符串,如何转换它们?
【问题讨论】:
-
你想提取字符串列表吗?
.tolist()会这样做。这些已经是 UTF-8 中的字符串 -
dtype='<U8'是字符串数据类型