溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時間:2020-08-26 02:36:57 來源:腳本之家 閱讀:706 作者:宿永杰 欄目:開發(fā)技術(shù)

如下所示:

# 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

接下來用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全表查詢定位某個值所在行列的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI