Python报错TypeError怎么解决

将mat数据导入至Python中,对数据集的实部进行提取时报错TypeError: float() argument must be a string or a number, not 'dict',怎么解决?
如何将float转换为string or a number?

这个报错TypeError: float() argument must be a string or a number, not 'dict'
是说float()的参数必须是字符串或数字,而不是字典“dict”
你给float()中传的参数是字典

对字典、列表等序列数据转换为float类型数据时需遍历其元素再转换,同时要转换的数据中不能含有None和非数值型字符串等,否则会报错。举个简单例子:

data={'value':[0.5,'20.3',16]}
data_values=[float(x) for x in data['value']]
print(data_values)

TypeError: float() argument must be a string or a number, not 'dict'是说你的float()函数里面的内容是dict(字典),而float函数只能将字符串(例如 '9' )或者数字(例如 9 )转化为浮点类型(例如 9.0),你需要查看一下你的字典的键是不是可以转化为浮点型数字,或者你的值是否可以转化为数字