0% found this document useful (0 votes)
10 views

Print Print Print Print Print Print Print Print Int Input 1 2 3 4 5 6 7

Uploaded by

a2286011562
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Print Print Print Print Print Print Print Print Int Input 1 2 3 4 5 6 7

Uploaded by

a2286011562
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import pandas as pd

def access_csv():
print("\n\nList of car companies:\nSelect any one option(1-7)")
print("1. Maruti Suzuki")
print("2. Tata motors")
print("3. Hyundai Motor India")
print("4. Mahindra & Mahindra")
print("5. Kia")
print("6. Toyota")
print("7. MG Motors")
choice=int(input("Enter your choice as code: "))
dict1={1:"maruti",2:"tata",3:"hyundai",4:"mahindra",5:"kia",6:"toyota",7:"mg"}
company= dict1[choice]
df=pd.read_csv(f'C:\\Users\\adity\\Downloads\\New folder\\{company}.csv')
df = df.apply(lambda x: x.str.lower() if x.dtype == "object" else x)
df.columns = df.columns.str.lower()
return df, company

def printdf(df,company):
print(f'\n\nAll the records of {company.upper()}:')
df1 = df.apply(lambda x: x.str.upper() if x.dtype == "object" else x)
df1.columns = df.columns.str.title()
print(df1,'\n')

def create_new():
df,company=access_csv()
model=input('Enter Model Name of a Car: ')
body=input('Enter Body Type of a Car: ')
carname=input('Enter Name of a Car: ')
engine=input('Enter Engine cubic capacity of a Car: ')
torque=input('Enter Torque of a Car: ')
power=input('Enter Horsepower of a Car: ')
drivetype=input('Enter Drivetype of a Car: ')
trasmissiontype=input('Enter Trasmissiontype of a Car: ')

df.loc[len(df)]=[model,body,carname,engine,torque,power,drivetype,trasmissiontype]
df.to_csv(f'C:\\Users\\adity\\Downloads\\New folder\\{company}.csv',
index=False)

def display():
df,company=access_csv()
printdf(df,company)

def Modify():
df,company=access_csv()
printdf(df,company)
carname=input("Enter Car name").lower()
df1=df[df['car name'].str.contains(carname, case=False, na=False)]
printdf(df1,carname)
model=input("Enter Model Name: ")
body=input('Enter New Body Type of a Car: ')
carname=input('Enter New Name of a Car: ')
engine=input('Enter New Engine cubic capacity of a Car: ')
torque=input('Enter New Torque of a Car: ')
power=input('Enter New Horsepower of a Car: ')
drivetype=input('Enter New Drivetype of a Car: ')
transmissiontype=input('Enter New Trasmissiontype of a Car: ')
df.loc[df['model']==model,'body type']=body
df.loc[df['model']==model,'car name']=carname
df.loc[df['model']==model,'engine']= engine
df.loc[df['model']==model,'torque']=torque
df.loc[df['model']==model,'power']=power
df.loc[df['model']==model,'drive type']=drivetype
df.loc[df['model']==model,'transmission type']=transmissiontype
df.to_csv(f'C:\\Users\\adity\\Downloads\\New folder\\{company}.csv',
index=False)

def Delete():
df,company=access_csv()
printdf(df,company)
carname=input("Enter Car name").lower()
df1=df[df['car name'].str.contains(carname, case=False, na=False)]
printdf(df1,carname)
model=input("Enter Model Name")
df = df[df['model'] != model]
df.to_csv(f'C:\\Users\\adity\\Downloads\\New folder\\{company}.csv',
index=False)

def main_menu():
print("\nMenu Options:")
print("1. Create_new")
print("2. Display")
print("3. Modify")
print("4. Delete a record")
print("5. Exit Program")

if __name__ == "__main__":
while True:
main_menu()
choice = input("Please select an option (1-5): ")

if choice == '1':
create_new()
elif choice == '2':
display()
elif choice == '3':
Modify()
elif choice == '4':
Delete()
elif choice == '5':
print("Exiting the program.")
break
else:
print("Invalid choice. Please try again.")

import pandas as pd

# Set the maximum width for each column


pd.set_option('display.width', 1000) # Adjust the width as needed

# Ensure all columns are shown in a single line


pd.set_option('display.max_columns', None)

You might also like