我从Quantopian api调用了以下数据并收到了以下数据:

{Equity(25600, symbol=u'LPHI', asset_name=u'LIFE PARTNERS HOLDINGS INC', exchange=u'NASDAQ', start_date=Timestamp('2003-10-21 00:00:00+0000', tz='UTC'), end_date=Timestamp('2015-03-27 00:00:00+0000', tz='UTC'), first_traded=None, auto_close_date=Timestamp('2015-04-01 00:00:00+0000', tz='UTC'), exchange_full=u'NASDAQ GLOBAL SELECT MARKET'): [Event({'status': 0, 'created': Timestamp('2010-04-01 13:31:00+0000', tz='UTC'), 'limit_reached': False, 'stop': None, 'reason': None, 'stop_reached': False, 'commission': 0, 'amount': 8923, 'limit': None, 'sid': Equity(25600, symbol=u'LPHI', asset_name=u'LIFE PARTNERS HOLDINGS INC', exchange=u'NASDAQ', start_date=Timestamp('2003-10-21 00:00:00+0000', tz='UTC'), end_date=Timestamp('2015-03-27 00:00:00+0000', tz='UTC'), first_traded=None, auto_close_date=Timestamp('2015-04-01 00:00:00+0000', tz='UTC'), exchange_full=u'NASDAQ GLOBAL SELECT MARKET'), 'dt': Timestamp('2010-04-01 13:31:00+0000', tz='UTC'), 'id': 'effc428d025c4bf69ec59cd6f225d8a7', 'filled': 0})]}


现在我只需要数据的第一个数字。在这种情况下是25600
你们能让我知道我该如何提取吗?

非常感谢

最佳答案

一个肮脏的方法是

s = a.find('Equity') # where a is your string you get from quantopian

e = a.find('symbol')

print(a[s+7:e-2])


我找到EquitySymbol的索引,然后在适当的索引之后使用切片运算符获取中间的任何内容。

您可以使用str(response)执行索引操作,将返回值从Quantopian转换为字符串

关于python - 如何提取值(value),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44931704/

10-12 18:44