我正在从excel导入数据。矩阵是浮点(或可转换为浮点的字符串)和字符串的混合体,我需要对浮点进行操作,忽略字符串。如何将字符串设置为0?你知道吗
示例: 我有一个数组a: a=np.数组(['1'、'5'、'day']、['month'、'5'、'7.3'])
我要将该数组转换为: a=([1,.5,0],[0,.5,7.3])
编辑: 对我来说是这样的:
shape = np.shape(a)
for i in range(shape[0]):
for j in range(shape[1]):
if np.core.defchararray.isdigit((np.core.defchararray.replace(a[i,j],'.','')))==False:
a[i,j]=0
a=np.array(a,float)
下面是一种使用^{} 和^{} 组合的方法-
样本运行-
相关问题 更多 >
编程相关推荐