pandas
import pandas as pd
def get_index(accno):
df = pd.read_csv("bank.csv")
return df[df["Account Number"] == accno].index[0]
def append():
df = pd.read_csv("bank.csv")
dff = pd.read_csv("contact.csv")
name = input("Enter the name of the account holder: ")
accno = int(input("Enter the account number: "))
print("Enter the account type:")
print("1. Savings")
print("2. Current")
ch = int(input("Enter your choice: "))
if ch == 1:
acctype = "Savings"
elif ch == 2:
acctype = "Current"
else:
acctype = "Savings"
adhaar = int(input("Enter the adhaar number: "))
balance = int(input("Enter the balance: "))
contact = int(input("Enter the contact number: "))
dob = input("Enter the date of birth: ")
address = input("Enter the address: ")
df.loc[len(df)] = [name, accno, acctype, adhaar, balance]
dff.loc[len(dff)] = [name, adhaar, contact, dob, address]
df.to_csv("bank.csv", index=False)
dff.to_csv("contact.csv", index=False)
print("Record appended successfully")
def delete():
df = pd.read_csv("bank.csv")
accno = int(input("Enter the account number: "))
df = df[df["Account Number"] != accno]
df.to_csv("bank.csv", index=False)
print("Record deleted successfully")
def credit():
df = pd.read_csv("bank.csv")
accno = int(input("Enter the account number: "))
amount = int(input("Enter the amount to be credited: "))
df.loc[get_index(accno), "Balance"] += amount
df.to_csv("bank.csv", index=False)
print("Amount credited successfully")
def debit():
df = pd.read_csv("bank.csv")
accno = int(input("Enter the account number: "))
amount = int(input("Enter the amount to be debited: "))
df.loc[get_index(accno), "Balance"] -= amount
if (df.loc[get_index(accno), "Balance"] < 0 and df.loc[get_index(accno), "Account Type"] == "Savings"):
print("Insufficient balance")
return
df.to_csv("bank.csv", index=False)
print("Amount debited successfully")
def display():
df = pd.read_csv("bank.csv")
accno = int(input("Enter the account number: "))
print(df[df["Account Number"] == accno])
if not os.path.exists("bank.csv"):
df = pd.DataFrame(
columns=["Name", "Account Number", "Account Type", "Adhaar Number", "Balance"])
df.to_csv("bank.csv", index=False)
if not os.path.exists("contact.csv"):
df = pd.DataFrame(
columns=["Name", "Adhaar Number", "Contact Number", "DOB", "Address"])
df.to_csv("contact.csv", index=False)
while True:
print("1. Append record")
print("2. Delete record")
print("3. Credit")
print("4. Debit")
print("5. Display account details")
print("6. Merge tables")
print("7. Exit")
ch = int(input("Enter your choice: "))
if ch == 1:
append()
elif ch == 2:
delete()
elif ch == 3:
credit()
elif ch == 4:
debit()
elif ch == 5:
display()
elif ch == 6:
df = pd.read_csv("bank.csv")
dff = pd.read_csv("contact.csv")
df = pd.merge(df, dff, on=["Name", "Adhaar Number"])
df.to_csv("merge.csv", index=False)
print("Tables merged successfully")
elif ch == 7:
sys.exit()
else:
print("Invalid choice")
input("\nPress enter to continue")