Example of defining a function to query an ID value when entering a Python coding ID.

Asked 2 years ago, Updated 2 years ago, 124 views

Hello, I have a question.

df.[df["IDColumn"] == "ID"]

If you enter "the corresponding ID" here, you can simply see the value accompanied by the ID.

In addition to this method,

Please define a function using the def statement and give an example of a coding sentence that expresses the value attached when entering the ID.

Def statement is still poor, so if you want to express a little different method, there will be some restrictions, so if you give me an example of coding, I think it will be helpful.

Thank you!

python def

2022-09-20 21:57

1 Answers

import pand as pd
data = {'id':['admin','guest'],
        'pass':['p@assword','guest'],
        'name':['howoni','guest']}
df = pd.DataFrame(data)

def checkid(name):
    print (df.loc[ df['id'] == name, ['id','pass','name']])

checkid('guest')

#result
#      #      id   pass   name
#1  guest  guest  guest


2022-09-20 21:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.