如何提取价值

时间:2017-07-05 16:36:53

标签: python api pandas

我已经从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 你能告诉我怎样才能提取它吗?

非常感谢和亲切的问候

1 个答案:

答案 0 :(得分:3)

执行此操作的肮脏方法是

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转换为字符串来执行索引