Pandas - 在整个数据框中查找特定值 [英] Pandas - find specific value in entire dataframe

查看:44
本文介绍了Pandas - 在整个数据框中查找特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,我想在所有列中搜索文本Apple"的值.我知道如何用一列做到这一点,但如何将其应用于所有列?我想把它做成一个函数,以便下次我可以直接用它来搜索其他日期帧中的其他值.

I have a dataframe and I want to search all columns for values that is text 'Apple'. I know how to do it with one column, but how can I apply this to ALL columns? I want to make it a function, so that next time I can directly use it to search for other values in other dateframes.

谢谢.

推荐答案

导入pandas库

import pandas as pd

文件的原始数据或 URL

raw_data = {'first_name': ['Mihir', 'Mihir', 'Raju', 'Johan', 'Johan'],
               'last_name': ['Patel', 'Patel', 'Ali', 'Khan', 'Khan'], 
               'age': [42, 42, 36, 24, 53]}
df = pd.DataFrame(raw_data, columns = ['first_name', 'last_name', 'age'])

找到价值

df.loc[df['first_name']=='Mihir']

这篇关于Pandas - 在整个数据框中查找特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆