【发布时间】:2019-11-25 09:02:54
【问题描述】:
大家好,我是 python 的新手,想知道如何在 Python 中专门搜索单词/数字,其结果是该单词来自的行。
staff.txt 包含类似的行信息
ID 名称 StartDate 角色
001 约翰 1-1-2001 Kitchenhand
002 迈克 2-1-2001 收银员
到目前为止,我的代码是这样的。我可以阅读 txt 文件,选择如何通过 ID 或电子邮件搜索员工。我只是迷失了如何编码它在 txt 文件中搜索 ID 的位。任何帮助或指导将不胜感激。
import random
choices = ["1","2"]
choice2a = random.choice(choices)
# reads txt file
df = pd.read_csv('staff.txt', 'w', delimiter='\t')
# deletes Unnamed columns
df = df.loc[:, ~df.columns.str.contains('^Unnamed')]
name= input("How would you like to search for staff?")
print ("1)ID")
print ("2)Email")
choice1 = input("Type Answer")#choice
if choice1 == "1" or choice1 == "1":
input("Type staff ID")
ID = ```
【问题讨论】:
标签: python python-3.x pandas