pandas全表查询定位某个值所在行列的方法
如下所示:
# 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])
或者用列表推导式:
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')]
相关推荐
三石 2020-10-30
roamer 2020-10-29
三石 2020-10-29
wangquannuaa 2020-10-15
wangquannuaa 2020-09-29
jzlixiao 2020-09-15
wangquannuaa 2020-08-30
三石 2020-08-23
逍遥友 2020-08-21
jzlixiao 2020-08-18
wangquannuaa 2020-08-17
QianYanDai 2020-08-16
cjsyrwt 2020-08-14
jzlixiao 2020-07-29
xirongxudlut 2020-07-20
mmmjyjy 2020-07-16
QianYanDai 2020-07-05
QianYanDai 2020-07-05
june0 2020-07-04