parent
daf34d6713
commit
39a2463b4a
@ -0,0 +1,88 @@
|
||||
import pandas as pd
|
||||
|
||||
|
||||
|
||||
# 1111添加学员信息
|
||||
def AddLearners(df):
|
||||
name = input("请输入学员姓名")
|
||||
sex = input("请输入学员性别")
|
||||
phone = input("请输入学员电话")
|
||||
# new_data = pd.DataFrame({"姓名":name,"性别":sex,"电话":phone})
|
||||
new_data = pd.DataFrame([[name,sex,phone]],columns=["姓名","性别","电话"])
|
||||
print(new_data)
|
||||
df = df._append(new_data,ignore_index=True)
|
||||
return df
|
||||
|
||||
|
||||
# 2222删除学员信息
|
||||
def DeleteALearner(df):
|
||||
name = input("请输入要删除的姓名")
|
||||
df = df[df["姓名"]!=name]
|
||||
return df
|
||||
|
||||
|
||||
#3333 修改学员信息
|
||||
def ModifyLearnerInformation(df):
|
||||
name = input("请输入想修改的姓名")
|
||||
sex = input("请输入性别")
|
||||
phone = input("请输入手机号")
|
||||
# df[df["姓名"]==name]["性别"] = sex
|
||||
# df[df["姓名"]==name]["电话"] = phone
|
||||
df["性别"].mask(df["姓名"]==name,sex,inplace=True)
|
||||
df["电话"].mask(df["姓名"]==name,phone,inplace=True)
|
||||
# print(df)
|
||||
return df
|
||||
# 4444查询学员信息
|
||||
def QueryLearnerInformation(df):
|
||||
name = input("请输入查询的姓名")
|
||||
print(df[df["姓名"] == name])
|
||||
|
||||
|
||||
# 5555显示所有学员信息
|
||||
def DisplaysAllLearnerInformation(df):
|
||||
print(df)
|
||||
|
||||
|
||||
|
||||
# 保存学员信息
|
||||
def SaveLearnerInformation(df):
|
||||
df.to_csv("students.csv",encoding="utf-8",index=False)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
df = pd.read_csv("students.csv", encoding='utf-8')
|
||||
df.set_index("姓名")
|
||||
print("请选择如下功能:\n"
|
||||
"1: 添加学员\n"
|
||||
"2: 删除学员\n"
|
||||
"3: 修改学员信息\n"
|
||||
"4: 查询学员信息\n"
|
||||
"5: 显示所有学员信息\n"
|
||||
"6: 保存学员信息\n"
|
||||
"7: 退出系统\n")
|
||||
while True:
|
||||
|
||||
x = int(input("请输入宁需要的功能序号:"))
|
||||
if x ==1 :
|
||||
df = AddLearners(df)
|
||||
elif x == 2:
|
||||
df = DeleteALearner(df)
|
||||
elif x==3:
|
||||
df = ModifyLearnerInformation(df)
|
||||
elif x==4:
|
||||
QueryLearnerInformation(df)
|
||||
elif x== 5 :
|
||||
DisplaysAllLearnerInformation(df)
|
||||
elif x==6:
|
||||
SaveLearnerInformation(df)
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in new issue