欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pandas全表查詢定位某個(gè)值所在行列的方法

 更新時(shí)間:2018年04月12日 11:09:26   作者:宿永杰  
下面小編就為大家分享一篇pandas全表查詢定位某個(gè)值所在行列的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

如下所示:

# create a dataframe with an integer feature and a categorical string feature
demo_df = pd.DataFrame({'Integer Feature': [0, 1, 2, 1], 'Categorical Feature': ['socks', 'fox', 'socks', 'box']})
demo_df

接下來(lái)用for遍歷:

for indexs in demo_df.index: 
  for i in range(len(demo_df.loc[indexs].values)): 
    if(demo_df.loc[indexs].values[i] =='fox'): 
      print(indexs,i) 
      print(demo_df.loc[indexs].values[i]) 

或者用列表推導(dǎo)式:

Categorical FeatureInteger Feature0socks01fox12socks23box1 
[ (indexs,i) for indexs in demo_df.index for i in range(len(demo_df.loc[indexs].values)) if(demo_df.loc[indexs].values[i] =='fox')] 

以上這篇pandas全表查詢定位某個(gè)值所在行列的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論