【发布时间】:2020-10-10 02:43:52
【问题描述】:
#search for option given symbol and expiration date
list_of_dicts =
r.options.find_options_for_stock_by_expiration(symbol,expirationDate,optionType='put')
print(list_of_dicts)
#convert list of dictionaries into single list by parameter given
parameter_a = 'bid_price'
new_list = [f[parameter_a] for f in list_of_dicts]
print(new_list)
将字典列表 (list_of_dicts) 转换为单个列表后,我得到了一个投标价格字符串列表:
['7.800000', '6.300000', '6.800000', '7.300000', '0.000000', '0.000000', '0.000000', '0.000000']
我的问题是,如何将此字符串列表转换为浮点数列表? 基本上我需要看到的是这样的:
[7.800000, 6.300000, 6.800000, 7.300000, 0.000000, 0.000000, 0.000000, 0.000000]
另外,如果列表中还包含“无”,我该怎么办?
【问题讨论】:
-
那些不是
floats,不是ints? -
对不起,它们是花车,是的
-
您想保留
Nones,还是删除它们? -
实际消除它们
-
哇哦,谢谢!
标签: python list dictionary integer nonetype