2016-02-28 239 views
-1

我有以下的熊貓數據框: enter image description here獲得熊貓據幀值

比方說,我有id = 16,想與它相關的search_term。我將如何解壓縮?

+0

^這不起作用? –

+1

'df [df ['id'] == 16] ['search_term']' –

+0

在您將問題扔到這裏之前,請多做一點自己的研究。一些參考:http://pandas.pydata.org/pandas-docs/stable/indexing.html –

回答

1

您可以使用ixloc

print df 
    id product_id product_title  search_term relevance 
0 2  100001 Simpsom Strong anglebracket  3.00 
1 3  100001 Simpsom Strong  ibracket  2.50 
2 16  100005  Delta Vero rainshowerhead  2.33 
df = df.ix[df['id']==16, 'search_term'] 
print df 
2 rainshowerhead 
Name: search_term, dtype: object 
df = df.loc[df['id']==16, 'search_term'] 
print df 
2 rainshowerhead 
Name: search_term, dtype: object 

Docs - 最後一段(In [126])。

或者你可以使用從評論Gustavo Bezerra解決方案:

df[df['id']==16]['search_term']