-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
190 lines (152 loc) · 6.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
from tkinter import *
from tkinter.ttk import *
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
import pandas as pds
#developer:ravi
#demo version
#packages for excel (xlrd,openpyxl)
#class Root is main core that connects to all backend logics
class Root(Tk):
#__init__ constructor
def __init__(self):
super(Root, self).__init__()
self.title("ismart data filter")
self.wm_iconbitmap('icon.ico')
self.geometry("330x280")
w = Canvas()
w.pack()
w.create_line(200,30, 200, 260, fill="black", width=1)
style = Style()
style.configure('y.TButton', font = ('calibri', 15, 'bold'), borderwidth = '4',foreground='red')
style.configure('w.TButton', font = ('calibri', 11, 'bold'), foreground = 'black')
self.main()
#frontend buttons
def main(self):
buttonExample1 = Button(text="select file",
style='y.TButton',command=self.import_data)
buttonExample1.place(x=20, y=100)
buttonExample2 = Button(text="filter",
style= 'w.TButton',command=self.filter)
buttonExample2.place(x=225,y=50)
buttonExample3 = Button(text="output",
style="w.TButton",command=self.output)
buttonExample3.place(x=225,y=190)
#import_csv_Dat contains logics of filtering process
def import_data(self):
global file_path
file_path = askopenfilename()
if file_path.endswith('.xlsx'):
self.xlsxfile()
elif file_path.endswith('.csv'):
self.csvfile()
else:
print("cannot find excel file and csv file")
def xlsxfile(self):
newData = pds.read_excel(file_path)
pd_xl_file = pds.ExcelFile(file_path)
print(newData)
parsing = pd_xl_file.parse("Sheet1")
col_count = len(parsing.axes[1])
print("no of collumns is",col_count)
row = newData.head(0)
datacol = newData.columns
print("selected file is under process")
window = Tk()
window.wm_iconbitmap('icon.ico')
window.title("filtering process")
window.geometry('350x200')
# Option menu variable
list_col=[]
for i in range(col_count):
col=newData.columns[i]
list_col.insert(i,col)
def coldata():
specficcol=newData[[optionVar.get()]]
print("Selected value :", optionVar.get())
print("selected column values:", specficcol)
def create_excel():
firstval = int(E1.get())
secondval = int(E2.get())
optionval = optionVar.get()
df_tech_select_columns = newData.loc[(newData[optionval] >= firstval) & (newData[optionval] <= secondval )]
print(df_tech_select_columns)
df_tech_select_columns.to_excel("output/excel/test.xlsx")
print("entered column no",i,"column value is",col)
print(list_col)
l1 = Label(window, text='Select Column:', width=15 )
l1.place(x=45,y=25)
optionVar = StringVar(root)
optionVar.set("select option")
option = OptionMenu(window, optionVar, *list_col)
option.place(x=130,y=25)
l2 = Label(window, text='advanced filter :', width=15 )
l2.place(x=24,y=100)
selnum= StringVar(root)
E1 = Entry(window,width=10)
E1.place(x = 120,y = 100)
l3 = Label(window, text='from', width=15 )
l3.place(x=130,y=125)
E2 = Entry(window,width=10)
E2.place(x = 200,y = 100)
l4 = Label(window, text='upto', width=15 )
l4.place(x=215,y=125)
btnShow = Button(window, text="Column values", command=coldata)
btnShow.place(x=130,y=50)
btnShow2 = Button(window, text="Submit",command=create_excel)
btnShow2.place(x=130,y=150)
window.mainloop()
def csvfile(self):
newData = pds.read_csv(file_path)
print(newData)
list_of_column_names = list(newData.columns)
print("first row values:",list_of_column_names)
#gui frontend for csv filtering
window = Tk()
window.wm_iconbitmap('icon.ico')
window.title("filtering process")
window.geometry('350x200')
#coldata function prints the selected column values
def coldata():
specficcol=newData[[optionVar.get()]]
print("Selected value :", optionVar.get())
print("selected column values:", specficcol)
#create_csv function filter the records
def create_csv():
firstval = int(E1.get())
secondval = int(E2.get())
optionval = optionVar.get()
df_tech_select_columns = newData.loc[(newData[optionval] >= firstval) & (newData[optionval] <= secondval )]
print(df_tech_select_columns)
df_tech_select_columns.to_csv("output/csv/test.csv")
l1 = Label(window, text='Select Column:', width=15 )
l1.place(x=45,y=25)
optionVar = StringVar(root)
optionVar.set("select option")
option = OptionMenu(window, optionVar, *list_of_column_names)
option.place(x=130,y=25)
l2 = Label(window, text='advanced filter :', width=15 )
l2.place(x=24,y=100)
selnum= StringVar(root)
E1 = Entry(window,width=10)
E1.place(x = 120,y = 100)
l3 = Label(window, text='from', width=15 )
l3.place(x=130,y=125)
E2 = Entry(window,width=10)
E2.place(x = 200,y = 100)
l4 = Label(window, text='upto', width=15 )
l4.place(x=215,y=125)
btnShow = Button(window, text="Column values",command = coldata)
btnShow.place(x=130,y=50)
btnShow2 = Button(window, text="Submit",command = create_csv)
btnShow2.place(x=130,y=150)
window.mainloop()
#data filter considered as filtering data logic
def filter(self):
self.import_data()
#output considered as showing filtered data
def output(self):
# Create Object
print("under process")
root = Root()
root.mainloop()