Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import tkinter as tk
- import numpy as np
- from tabulate import tabulate
- phones = pd.read_csv('data.csv')
- phones.drop(columns=['ImageUrl',"Unnamed: 0"],inplace = True)
- pd.options.display.max_columns = None
- pd.set_option('display.max_rows', 20)
- pd.set_option('display.max_columns', 50)
- pd.set_option('display.width', 100)
- phones.index.name = 'ID'
- root = tk.Tk()
- v = tk.StringVar()
- columns = list(phones)
- #Input validation for the comparison function
- def inputValid(num,maxx):
- validInput = False
- while validInput == False:
- try:
- num = int(input('Input ID '+num+': '))
- if num > 0 and num < maxx:
- return num
- validInput = True
- else:
- print('Invalid ID number.')
- except ValueError:
- print('Invalid entry.')
- #Function which will display the table in a text window
- def textBox(x, h, w):
- xscrollbar = tk.Scrollbar(root, orient="horizontal")
- yscrollbar = tk.Scrollbar(root)
- xscrollbar.pack(side="bottom", fill="x")
- yscrollbar.pack(side="right", fill="y")
- T = tk.Text(root, height=h, width=w, xscrollcommand=xscrollbar.set, yscrollcommand=yscrollbar.set)
- T.pack()
- T.insert(tk.END,tabulate(x,headers='keys',tablefmt='psql'))
- xscrollbar.config(command=T.xview)
- yscrollbar.config(command=T.yview)
- T.config(wrap="none")
- tk.mainloop()
- #Comparison function, asks user for two IDs and will display both in a text window
- def compare():
- phone1 = inputValid('1',1151)
- phone2 = inputValid('2',1151)
- temp = phones.query('ID=='+str(phone1)+' or ID=='+str(phone2))
- textBox(temp, 15, 200)
- def sort():
- valid = False
- while valid == False:
- sort = input("Enter column to sort by: ")
- if sort in columns:
- valid = True
- else:
- print("Invalid column name, please try again")
- phones.sort_values(by=[sort], inplace=True)
- sorts = phones[["Name", sort]]
- textBox(sorts, 50, 150)
- def addFilter():
- x = v.get()
- filtered = phones
- print(filtered)
- if type(phones[x][0]) is np.int64 or type(phones[x][0]) is np.float64:
- value = input("Enter minimum value to be filtered by: ")
- filtered = filtered.query(x+">"+value)
- elif type(phones[x][0]) is str:
- value = input("Enter value to be filtered by: ")
- print(value)
- filtered = filtered[filtered[x] == str(value)]
- elif type(phones[x][0]) is np.bool_:
- value = input("Filter by true or false: ")
- filtered = filtered.query(x+"=="+value)
- textBox(filtered, 50, 150)
- def filtering():
- values = {"Cost" : "Cost",
- "Multi Camera" : "multiCamera",
- "Rear Camera" : "rearCamera",
- "Front Camera" : "frontCamera",
- "Size (cm)" : "size_cm",
- "Size (inches)" : "size_inch",
- "Battery Capacity" : "batterySize",
- "Battery Type" : "batteryType",
- "RAM" : "RAM",
- "ROM" : "ROM",
- "Expandable Storage" : "Expandable"}
- for text, value in values.items():
- b = tk.Radiobutton(root, text=text, variable=v, value=value).pack(anchor="w")
- add_filter = tk.Button(root, text="Add Filter", command=addFilter).pack()
- tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement