1
0

Me_learn.py 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627
  1. import tkinter
  2. from tkinter.filedialog import askopenfilename, asksaveasfilename
  3. import tkinter.messagebox
  4. from Data_Science import Learn
  5. import webbrowser
  6. import os
  7. from tkinter.scrolledtext import ScrolledText
  8. import chardet
  9. # 数据清洗
  10. Clean_Text = '''#输入你的数据清洗执行代码
  11. Done_Row=[] #输入操作的行号
  12. Done_Column=[] #输入操作的列号
  13. axis=True #True-操作行,False-操作列
  14. name='' #方法代号
  15. def check(data, row, column, get, R, C): #检查方法
  16. return True
  17. def done(data, row, column, get, R, C): #应用修正方法
  18. return DEL
  19. '''
  20. Clean_Help = '''
  21. 使用Python代码进行数据清洗
  22. 1)代码结构
  23. Done_Row=[] 代码用来检测的数据的列号
  24. Done_Column=[] 代码用来检测的数据的行号
  25. 不在以上指定范围内的数据将不会被检测,若为空则整个表格检测
  26. axis 执行删除方法时删除行或者列
  27. name 方法代号
  28. check 检查方法
  29. 输入:当前的值(输入的是一个值而不是一行(列)或整个列表)
  30. 输入:row和column当前值来自的行号(row)和列号(column)
  31. 输入:get当前检查的所有数据:类型是表格
  32. 输入:R和C当前值所来自的行和列的所有数据:类型是一维表格
  33. 输出:输出布尔为True代表该值可以使用,输出布尔为假表示该值不可使用
  34. done 不可使用的数值改造方法
  35. 输入:内容同上
  36. 输出:改造值或者DEL
  37. DEL:代表删除改值所在的行(axis=True)或列(axis=False)
  38. 2)扩展
  39. 默认:pd-pandas,re-re[正则表达式],Sheet-包含所有表格,用Sheet['name']访问名字为name的表格(注意引号别漏了)
  40. 支持:可以使用import导入语句,支持python语法
  41. '''
  42. Args_Help = '''
  43. 输入python变量赋值代码:渲染设置
  44. title #设置标题:str
  45. vice_title #设置副标题:str
  46. show_Legend #是否显示图例:bool
  47. show_Visual_mapping #是否使用视觉映射:bool
  48. is_color_Visual_mapping #是否为颜色视觉映射:bool[否则为大小视觉映射]
  49. min_Visual_mapping #映射的最小值
  50. max_Visual_mapping #映射的最大值
  51. ......(我太懒了, 设置太多不想写了)
  52. '''
  53. # top = None
  54. # ML = None
  55. # Form_List = None
  56. # PATH = None
  57. # bg = None
  58. # ft1 = None
  59. # Stored_List = None
  60. # Clean_List = None
  61. # R_Dic = None
  62. # Over_Up = None
  63. # Over_Down = None
  64. #
  65. # Form_BOX = None
  66. # Index_BOX = None
  67. # Column_BOX = None
  68. # to_HTML_Type = None
  69. # Seq_Input = None
  70. # Code_Input = None
  71. # str_must = None
  72. # Index_must = None
  73. def Machine_learning():
  74. global top, ML, Form_List, PATH, bg, ft1, Stored_List, Clean_List, R_Dic, Over_Up, Over_Down,Learn_Dic
  75. R_Dic = {} # 保存了画图的List
  76. Learn_Dic = {} #保存数据处理
  77. PATH = os.getcwd()
  78. Form_List = []
  79. ML = Learn.Machine_Learner()
  80. top = tkinter.Tk()
  81. bg = '#FFFAFA' # 主颜色
  82. bbg = '#FFFAFA' # 按钮颜色
  83. fg = '#000000' # 文字颜色
  84. top["bg"] = bg
  85. FONT = ('黑体', 11) # 设置字体
  86. ft1 = ('黑体', 13)
  87. top.title('CoTan数据处理')
  88. top.resizable(width=False, height=False)
  89. top.geometry('+10+10') # 设置所在位置
  90. width_B = 13 # 标准宽度
  91. height_B = 2
  92. a_y = 0
  93. a_x = 0
  94. Stored_List = []
  95. Clean_List = []
  96. # 层叠多图
  97. Over_Down = None
  98. Over_Up = None
  99. tkinter.Button(top, bg=bbg, fg=fg, text='导入CSV', command=Add_CSV, font=FONT, width=width_B,
  100. height=height_B).grid(column=a_x, row=a_y,
  101. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  102. tkinter.Button(top, bg=bbg, fg=fg, text='导入Py', command=Add_Python, font=FONT, width=width_B,
  103. height=height_B).grid(column=a_x + 1, row=a_y,
  104. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  105. tkinter.Button(top, bg=bbg, fg=fg, text='导出CSV', command=to_CSV,font=FONT, width=width_B,
  106. height=height_B).grid(column=a_x + 2, row=a_y,sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  107. global name_Input
  108. a_y += 1
  109. tkinter.Label(top, text='表格名称:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  110. row=a_y) # 设置说明
  111. name_Input = tkinter.Entry(top, width=width_B)
  112. name_Input.grid(column=a_x + 1, row=a_y,columnspan=2, sticky=tkinter.E + tkinter.W)
  113. a_y += 1
  114. tkinter.Button(top, bg=bbg, fg=fg, text='删除表格',command=Del_Sheet, font=FONT, width=width_B,
  115. height=height_B).grid(column=a_x, row=a_y,
  116. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  117. tkinter.Button(top, bg=bbg, fg=fg, text='查看表格', command=Show, font=FONT, width=width_B,
  118. height=height_B).grid(column=a_x + 1, row=a_y,
  119. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  120. tkinter.Button(top, bg=bbg, fg=fg, text='查看单一表格', command=Show_One,font=FONT, width=width_B,
  121. height=height_B).grid(column=a_x + 2, row=a_y,
  122. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  123. global Form_BOX, Index_BOX, Column_BOX, to_HTML_Type, Seq_Input, Code_Input, str_must, Index_must
  124. a_y += 1
  125. to_HTML_Type = tkinter.IntVar() # 正,负,0
  126. lable = ['选项卡型', '可移动型', '自适应型'] # 复选框
  127. for i in range(3):
  128. tkinter.Radiobutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text=lable[i],
  129. variable=to_HTML_Type,
  130. value=i).grid(column=a_x + i, row=a_y, sticky=tkinter.W)
  131. str_must = tkinter.IntVar()
  132. Index_must = tkinter.IntVar()
  133. a_y += 1
  134. tkinter.Label(top, text='编码方式:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  135. row=a_y) # 设置说明
  136. Code_Input = tkinter.Entry(top, width=width_B)
  137. Code_Input.grid(column=a_x + 1, row=a_y, sticky=tkinter.E + tkinter.W)
  138. buttom = tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg,
  139. text='字符串类型',
  140. variable=str_must)
  141. buttom.grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  142. a_y += 1
  143. tkinter.Label(top, text='CSV分隔符:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  144. row=a_y) # 设置说明
  145. Seq_Input = tkinter.Entry(top, width=width_B)
  146. Seq_Input.grid(column=a_x + 1, row=a_y, sticky=tkinter.E + tkinter.W)
  147. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='重置列名',
  148. variable=Index_must).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  149. a_y += 1
  150. Form_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 5) # 显示符号
  151. Form_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  152. a_y += 5
  153. tkinter.Button(top, bg=bbg, fg=fg, text='查看行名', command=get_Index, font=FONT, width=width_B,
  154. height=height_B).grid(column=a_x, row=a_y,
  155. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  156. tkinter.Button(top, bg=bbg, fg=fg, text='查看列名', command=get_Column, font=FONT, width=width_B,
  157. height=height_B).grid(column=a_x + 1, row=a_y,
  158. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  159. tkinter.Button(top, bg=bbg, fg=fg, text='显示表格', command=Write_Sheet, font=FONT, width=width_B,
  160. height=height_B).grid(column=a_x + 2, row=a_y,
  161. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  162. global Max_Row, Max_Column
  163. a_y += 1
  164. tkinter.Label(top, text='最大显示行数:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  165. row=a_y) # 设置说明
  166. Max_Row = tkinter.Entry(top, width=width_B * 2)
  167. Max_Row.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  168. a_y += 1
  169. tkinter.Label(top, text='最大显示列数:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  170. row=a_y) # 设置说明
  171. Max_Column = tkinter.Entry(top, width=width_B * 2)
  172. Max_Column.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  173. # Row与Column Row是横行,tkinter布局中Row变大,表示所在行数变大,向下移动如:
  174. # 1,2,3,4,5,6
  175. # 7,8,9,a,b,c
  176. # 其中数字1-6是第一行,1-c是第二行,第二行在第一行下面,row变大向下移动(Row是横向行而不是横向移动) to 搞不清楚横行竖列的人
  177. a_y += 1
  178. Index_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 10) # 显示符号
  179. Index_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=10, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  180. global Des_Bool
  181. a_y += 10
  182. tkinter.Button(top, bg=bbg, fg=fg, text='查看数据分析', command=Show_Des, font=FONT, width=width_B,
  183. height=height_B).grid(column=a_x, row=a_y,
  184. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  185. tkinter.Button(top, bg=bbg, fg=fg, text='简单数据统计', command=Show_describe, font=FONT, width=width_B,
  186. height=height_B).grid(column=a_x + 1, row=a_y,
  187. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  188. Des_Bool = tkinter.IntVar() # 是否启用
  189. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='生成统计表格',
  190. variable=Des_Bool).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  191. a_x += 3
  192. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  193. a_x += 1
  194. a_y = 0
  195. tkinter.Label(top, text='【数据清洗】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  196. columnspan=3,
  197. row=a_y,
  198. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  199. global Slice_new, Column_Type, Row_Type, Column_clist, Row_clist
  200. Column_clist = []
  201. Row_clist = []
  202. label = ['启始(列号):', '终止(列):', '间隔(列):']
  203. for i in range(3):
  204. a_y += 1
  205. tkinter.Label(top, text=label[i], bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  206. row=a_y) # 设置说明
  207. Column_clist.append(tkinter.Entry(top, width=width_B * 2))
  208. Column_clist[-1].grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.W + tkinter.E)
  209. label = ['启始(行号):', '终止(行):', '间隔(行):']
  210. for i in range(3):
  211. a_y += 1
  212. tkinter.Label(top, text=label[i], bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  213. row=a_y) # 设置说明
  214. Row_clist.append(tkinter.Entry(top, width=width_B * 2))
  215. Row_clist[-1].grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.W + tkinter.E)
  216. a_y += 1
  217. Column_Type = tkinter.IntVar()
  218. lable = ['根据列号', '根据列名', '输入列号'] # 复选框
  219. for i in range(3):
  220. tkinter.Radiobutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text=lable[i],
  221. variable=Column_Type, value=i). \
  222. grid(column=a_x + i, row=a_y, sticky=tkinter.W)
  223. a_y += 1
  224. Row_Type = tkinter.IntVar()
  225. lable = ['根据行号', '根据行名', '输入行号'] # 复选框
  226. for i in range(3):
  227. tkinter.Radiobutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text=lable[i],
  228. variable=Row_Type, value=i). \
  229. grid(column=a_x + i, row=a_y, sticky=tkinter.W)
  230. a_y += 1
  231. Slice_new = tkinter.IntVar()
  232. tkinter.Button(top, bg=bbg, fg=fg, text='切片选定', command=Slice_Data, font=FONT, width=width_B,
  233. height=height_B).grid(column=a_x, row=a_y,
  234. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  235. tkinter.Button(top, bg=bbg, fg=fg, text='删除选定', command=Del_Data, font=FONT, width=width_B,
  236. height=height_B).grid(column=a_x + 1, row=a_y,
  237. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  238. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='生成新表格',
  239. variable=Slice_new).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  240. global Bool_E, Drop_Column
  241. a_y += 1
  242. tkinter.Label(top, text='布尔逻辑:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  243. row=a_y,
  244. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  245. Bool_E = tkinter.Entry(top, width=width_B * 2)
  246. Bool_E.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.W + tkinter.E)
  247. a_y += 1
  248. tkinter.Label(top, text='操作的列号:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  249. row=a_y,
  250. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  251. Drop_Column = tkinter.Entry(top, width=width_B * 2)
  252. Drop_Column.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.W + tkinter.E)
  253. a_y += 1
  254. tkinter.Button(top, bg=bbg, fg=fg, text='生成布尔表格', command=Make_BoolSheet, font=FONT, width=width_B,
  255. height=height_B).grid(column=a_x, row=a_y,
  256. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  257. tkinter.Button(top, bg=bbg, fg=fg, text='查看空值', command=is_Na, font=FONT, width=width_B,
  258. height=height_B).grid(column=a_x + 1, row=a_y,
  259. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  260. tkinter.Button(top, bg=bbg, fg=fg, text='清洗空值(按行)', command=Done_NaN, font=FONT, width=width_B,
  261. height=height_B).grid(column=a_x + 2, row=a_y,
  262. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  263. a_y += 1
  264. tkinter.Button(top, bg=bbg, fg=fg, text='添加执行方法', command=Add_Clean, font=FONT, width=width_B,
  265. height=height_B).grid(column=a_x, row=a_y,
  266. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  267. tkinter.Button(top, bg=bbg, fg=fg, text='删除执行方法', command=Del_Clean, font=FONT, width=width_B,
  268. height=height_B).grid(column=a_x + 1, row=a_y,
  269. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  270. tkinter.Button(top, bg=bbg, fg=fg, text='数据特征提取', command=DecisionTreeClassifier, font=FONT, width=width_B,
  271. height=height_B).grid(column=a_x + 2, row=a_y,
  272. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  273. global Done_CleanBox, Done_Func
  274. a_y += 1
  275. Done_CleanBox = tkinter.Listbox(top, width=width_B * 3, height=height_B * 2)
  276. Done_CleanBox.grid(column=a_x, row=a_y, columnspan=3, rowspan=2,
  277. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  278. a_y += 2
  279. tkinter.Button(top, bg=bbg, fg=fg, text='查看词典', command=Show_Help, font=FONT, width=width_B,
  280. height=height_B).grid(column=a_x, row=a_y,
  281. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  282. tkinter.Button(top, bg=bbg, fg=fg, text='恢复显示', command=get_InsertClean_Text, font=FONT, width=width_B,
  283. height=height_B).grid(column=a_x + 1, row=a_y,
  284. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  285. tkinter.Button(top, bg=bbg, fg=fg, text='执行数据清洗', command=Done_Clean, font=FONT, width=width_B,
  286. height=height_B).grid(column=a_x + 2, row=a_y,
  287. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  288. a_y += 1
  289. Done_Func = tkinter.Text(top, width=width_B * 3, height=height_B * 7)
  290. Done_Func.grid(column=a_x, row=a_y, columnspan=3, rowspan=7, sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S)
  291. Done_Func.insert('0.0', Clean_Text)
  292. a_y += 7
  293. tkinter.Button(top, bg=bbg, fg=fg, text='清空执行方法', command=Tra_Clean, font=FONT, width=width_B,
  294. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  295. tkinter.Button(top, bg=bbg, fg=fg, text='查看执行方法', command=get_CleanEXP, font=FONT, width=width_B,
  296. height=height_B).grid(column=a_x + 1, row=a_y,
  297. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  298. tkinter.Button(top, bg=bbg, fg=fg, text='导入执行方法', command=Open_Python, font=FONT, width=width_B,
  299. height=height_B).grid(column=a_x + 2, row=a_y,
  300. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  301. a_x += 3
  302. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  303. a_x += 1
  304. a_y = 0
  305. tkinter.Label(top, text='【数据可视化】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  306. columnspan=3,
  307. row=a_y,
  308. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  309. a_y += 1
  310. tkinter.Button(top, bg=bbg, fg=fg, text='生成柱状图', command=to_Bar, font=FONT, width=width_B,
  311. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  312. tkinter.Button(top, bg=bbg, fg=fg, text='生成3D柱状图', command=to_Bar3d, font=FONT, width=width_B,
  313. height=height_B).grid(column=a_x + 1, row=a_y,
  314. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  315. tkinter.Button(top, bg=bbg, fg=fg, text='生成折线图', command=to_Line, font=FONT, width=width_B,
  316. height=height_B).grid(column=a_x + 2, row=a_y,
  317. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  318. a_y += 1
  319. tkinter.Button(top, bg=bbg, fg=fg, text='生成3D折线图', command=to_Line3D, font=FONT, width=width_B,
  320. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  321. tkinter.Button(top, bg=bbg, fg=fg, text='生成象形柱状图', command=to_Pictorialbar, font=FONT, width=width_B,
  322. height=height_B).grid(column=a_x + 1, row=a_y, columnspan=2,
  323. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  324. a_y += 1
  325. tkinter.Button(top, bg=bbg, fg=fg, text='生成散点图', command=to_Scatter, font=FONT, width=width_B,
  326. height=height_B).grid(column=a_x, row=a_y,
  327. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  328. tkinter.Button(top, bg=bbg, fg=fg, text='生成3D散点图', command=to_Scatter3D, font=FONT, width=width_B,
  329. height=height_B).grid(column=a_x + 1, row=a_y,
  330. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  331. tkinter.Button(top, bg=bbg, fg=fg, text='生成箱形图', command=to_Boxpolt, font=FONT, width=width_B,
  332. height=height_B).grid(column=a_x + 2, row=a_y,
  333. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  334. a_y += 1
  335. tkinter.Button(top, bg=bbg, fg=fg, text='生成漏斗图', command=to_Funnel, font=FONT, width=width_B,
  336. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  337. tkinter.Button(top, bg=bbg, fg=fg, text='生成热力图', command=to_HeatMap, font=FONT, width=width_B,
  338. height=height_B).grid(column=a_x + 1, row=a_y,
  339. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  340. tkinter.Button(top, bg=bbg, fg=fg, text='生成饼图', command=to_Pie, font=FONT, width=width_B,
  341. height=height_B).grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  342. a_y += 1
  343. tkinter.Button(top, bg=bbg, fg=fg, text='生成多轴图', command=to_Parallel, font=FONT, width=width_B,
  344. height=height_B).grid(column=a_x, row=a_y,
  345. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  346. tkinter.Button(top, bg=bbg, fg=fg, text='生成极坐标图', command=to_Polar, font=FONT, width=width_B,
  347. height=height_B).grid(column=a_x + 1, row=a_y,
  348. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  349. tkinter.Button(top, bg=bbg, fg=fg, text='生成雷达图', command=to_Radar, font=FONT, width=width_B,
  350. height=height_B).grid(column=a_x + 2, row=a_y,
  351. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  352. a_y += 1
  353. tkinter.Button(top, bg=bbg, fg=fg, text='生成词云', command=to_WordCloud, font=FONT, width=width_B,
  354. height=height_B).grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  355. tkinter.Button(top, bg=bbg, fg=fg, text='生成关系图', command=to_Graph, font=FONT, width=width_B,
  356. height=height_B).grid(column=a_x + 1, row=a_y,
  357. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  358. tkinter.Button(top, bg=bbg, fg=fg, text='生成XY关系图', command=to_XY_Graph, font=FONT, width=width_B,
  359. height=height_B).grid(column=a_x + 2, row=a_y,
  360. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  361. a_y += 1
  362. tkinter.Button(top, bg=bbg, fg=fg, text='生成水球图', command=to_Liquid, font=FONT, width=width_B,
  363. height=height_B).grid(column=a_x, row=a_y, columnspan=2,
  364. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  365. tkinter.Button(top, bg=bbg, fg=fg, text='生成仪表图', command=to_Gauge, font=FONT, width=width_B,
  366. height=height_B).grid(column=a_x + 2, row=a_y,
  367. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  368. a_y += 1
  369. tkinter.Button(top, bg=bbg, fg=fg, text='生成日历图', command=to_Calendar, font=FONT, width=width_B,
  370. height=height_B).grid(column=a_x, row=a_y,
  371. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  372. tkinter.Button(top, bg=bbg, fg=fg, text='生成河流图', command=to_ThemeRiver, font=FONT, width=width_B,
  373. height=height_B).grid(column=a_x + 1, row=a_y,
  374. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  375. tkinter.Button(top, bg=bbg, fg=fg, text='生成旭日图', command=to_Sunburst, font=FONT, width=width_B,
  376. height=height_B).grid(column=a_x + 2, row=a_y,
  377. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  378. a_y += 1
  379. tkinter.Button(top, bg=bbg, fg=fg, text='生成桑基图', command=to_Sankey, font=FONT, width=width_B,
  380. height=height_B).grid(column=a_x, row=a_y,
  381. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  382. tkinter.Button(top, bg=bbg, fg=fg, text='生成树状图', command=to_Tree, font=FONT, width=width_B,
  383. height=height_B).grid(column=a_x + 1, row=a_y,
  384. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  385. tkinter.Button(top, bg=bbg, fg=fg, text='生成矩形树图', command=to_TreeMap, font=FONT, width=width_B,
  386. height=height_B).grid(column=a_x + 2, row=a_y,
  387. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  388. a_y += 1
  389. tkinter.Button(top, bg=bbg, fg=fg, text='生成Map地图', command=to_Map, font=FONT, width=width_B,
  390. height=height_B).grid(column=a_x, row=a_y,
  391. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  392. tkinter.Button(top, bg=bbg, fg=fg, text='生成Geo点地图', command=to_ScatterGeo, font=FONT, width=width_B,
  393. height=height_B).grid(column=a_x + 1, row=a_y,
  394. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  395. tkinter.Button(top, bg=bbg, fg=fg, text='生成Geo地图', command=to_Geo, font=FONT, width=width_B,
  396. height=height_B).grid(column=a_x + 2, row=a_y,
  397. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  398. a_y += 1
  399. tkinter.Button(top, bg=bbg, fg=fg, text='选择底图', command=Over_Down_Add, font=FONT, width=width_B,
  400. height=height_B).grid(column=a_x, row=a_y,
  401. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  402. tkinter.Button(top, bg=bbg, fg=fg, text='选择顶图', command=Over_UP_Add, font=FONT, width=width_B,
  403. height=height_B).grid(column=a_x + 1, row=a_y,
  404. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  405. tkinter.Button(top, bg=bbg, fg=fg, text='生成层叠图', command=to_OverLap, font=FONT, width=width_B,
  406. height=height_B).grid(column=a_x + 2, row=a_y,
  407. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  408. a_y += 1
  409. global R_BOX, Args_Input, Over_BOX
  410. Over_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 2)
  411. Over_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=2, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  412. a_y += 1
  413. tkinter.Button(top, bg=bbg, fg=fg, text='渲染HTML', command=Draw, font=FONT, width=width_B,
  414. height=height_B).grid(column=a_x, row=a_y,
  415. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  416. tkinter.Button(top, bg=bbg, fg=fg, text='单独渲染HTML', command=Draw_One, font=FONT, width=width_B,
  417. height=height_B).grid(column=a_x + 1, row=a_y,
  418. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  419. tkinter.Button(top, bg=bbg, fg=fg, text='删除渲染', command=Del_R_BOX, font=FONT, width=width_B,
  420. height=height_B).grid(column=a_x + 2, row=a_y,
  421. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  422. a_y += 1
  423. R_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B)
  424. R_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=2, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  425. a_y += 2
  426. global Draw_asWell
  427. Draw_asWell = tkinter.IntVar()
  428. tkinter.Button(top, bg=bbg, fg=fg, text='清空渲染', command=Tra_RDic, font=FONT, width=width_B,
  429. height=height_B).grid(column=a_x, row=a_y,
  430. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  431. tkinter.Button(top, bg=bbg, fg=fg, text='导入渲染', command=Import_c, font=FONT, width=width_B,
  432. height=height_B).grid(column=a_x + 1, row=a_y,
  433. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  434. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='马上渲染',
  435. variable=Draw_asWell).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  436. a_y += 1
  437. Args_Input = tkinter.Text(top, width=width_B * 3, height=height_B * 7)
  438. Args_Input.grid(column=a_x, row=a_y, columnspan=3, rowspan=7, sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S)
  439. a_y += 7
  440. tkinter.Button(top, bg=bbg, fg=fg, text='查看词典',command=Show_Help, font=FONT, width=width_B,
  441. height=height_B).grid(column=a_x, row=a_y,
  442. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  443. tkinter.Button(top, bg=bbg, fg=fg, text='恢复显示',command=Show_Help, font=FONT, width=width_B,
  444. height=height_B).grid(column=a_x + 1, row=a_y, columnspan=2,
  445. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  446. a_x += 3
  447. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  448. a_x += 1
  449. a_y = 0
  450. tkinter.Label(top, text='【行名与列名】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  451. columnspan=3,
  452. row=a_y,
  453. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  454. global replace_Dic, Repalce_RC, replace_iloc, Date_Input, RC_Type
  455. a_y += 1
  456. Repalce_RC = tkinter.IntVar()
  457. lable = ['(列数据)调整行名', '(行数据)调整列名'] # 复选框
  458. for i in range(2):
  459. tkinter.Radiobutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text=lable[i],
  460. variable=Repalce_RC, value=i).grid(column=a_x + i, row=a_y, sticky=tkinter.W)
  461. tkinter.Button(top, bg=bbg, fg=fg, text='植入行(列)号', command=num_withName, font=FONT, width=width_B, height=height_B). \
  462. grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  463. a_y += 1
  464. RC_Type = []
  465. lable = ['保留原值', '保留新值'] # 复选框
  466. for i in range(2):
  467. RC_Type.append(tkinter.IntVar())
  468. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text=lable[i],
  469. variable=RC_Type[-1]).grid(column=a_x + i, row=a_y, sticky=tkinter.W)
  470. tkinter.Button(top, bg=bbg, fg=fg, text='统一行(列)号', command=num_toName, font=FONT, width=width_B, height=height_B). \
  471. grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  472. a_y += 1
  473. tkinter.Label(top, text='替换字典:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  474. row=a_y) # 设置说明
  475. replace_Dic = tkinter.Entry(top, width=width_B * 2)
  476. replace_Dic.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  477. a_y += 1
  478. tkinter.Label(top, text='替换列(行):', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  479. row=a_y) # 设置说明
  480. replace_iloc = tkinter.Entry(top, width=width_B * 2)
  481. replace_iloc.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  482. a_y += 1
  483. tkinter.Button(top, bg=bbg, fg=fg, text='执行替换已有列(行)操作', command=Change_Index, font=FONT, width=width_B * 2,
  484. height=height_B). \
  485. grid(column=a_x, columnspan=2, row=a_y, sticky=tkinter.E + tkinter.W)
  486. tkinter.Button(top, bg=bbg, fg=fg, text='执行替换操作', command=Replace_Index, font=FONT, width=width_B, height=height_B). \
  487. grid(column=a_x + 2, row=a_y, sticky=tkinter.E + tkinter.W)
  488. label = ['起点', '终点', '间隔']
  489. Date_Input = []
  490. for i in range(3):
  491. a_y += 1
  492. tkinter.Label(top, text='时间序列' + label[i], bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(
  493. column=a_x, row=a_y) # 设置说明
  494. Date_Input.append(tkinter.Entry(top, width=width_B * 2))
  495. Date_Input[-1].grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  496. global Date_Type
  497. a_y += 1
  498. Date_Type = tkinter.IntVar()
  499. tkinter.Button(top, bg=bbg, fg=fg, text='刷入Date序列', command=Date_Index, font=FONT, width=width_B, height=height_B). \
  500. grid(column=a_x, row=a_y, sticky=tkinter.E + tkinter.W)
  501. tkinter.Button(top, bg=bbg, fg=fg, text='刷入Time序列', command=Time_index, font=FONT, width=width_B, height=height_B). \
  502. grid(column=a_x + 1, row=a_y, sticky=tkinter.E + tkinter.W)
  503. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='使用间隔',
  504. variable=Date_Type).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  505. global Dtype_Column, Dtype_Input, Dtype_Wrong, Dtype_Func
  506. a_y += 1
  507. tkinter.Label(top, text='【数据类型管理】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  508. columnspan=3,
  509. row=a_y,
  510. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  511. a_y += 1
  512. tkinter.Label(top, text='修改(列号):', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  513. row=a_y) # 设置说明
  514. Dtype_Column = tkinter.Entry(top, width=width_B * 2)
  515. Dtype_Column.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  516. a_y += 1
  517. tkinter.Label(top, text='数据类型:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  518. row=a_y) # 设置说明
  519. Dtype_Input = tkinter.Entry(top, width=width_B * 2)
  520. Dtype_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  521. a_y += 1
  522. tkinter.Label(top, text='错误值:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  523. row=a_y) # 设置说明
  524. Dtype_Wrong = tkinter.Entry(top, width=width_B * 2)
  525. Dtype_Wrong.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  526. a_y += 1
  527. tkinter.Button(top, bg=bbg, fg=fg, text='执行转换', command=DTYPE, font=FONT, width=width_B,
  528. height=height_B).grid(column=a_x, row=a_y,
  529. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  530. Dtype_Func = tkinter.IntVar() # 正,负,0
  531. lable = ['硬转换', '软转换'] # 复选框
  532. for i in range(2):
  533. tkinter.Radiobutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text=lable[i],
  534. variable=Dtype_Func, value=i).grid(column=a_x + 1 + i, row=a_y, sticky=tkinter.W)
  535. a_y += 1
  536. tkinter.Label(top, text='【排序操作】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  537. columnspan=3,
  538. row=a_y) # 设置说明
  539. a_y += 1
  540. tkinter.Button(top, bg=bbg, fg=fg, text='.T', command=T, font=FONT, width=width_B,
  541. height=height_B).grid(column=a_x, row=a_y,
  542. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  543. tkinter.Button(top, bg=bbg, fg=fg, text='按行名排序', command=Stored_Row, font=FONT, width=width_B,
  544. height=height_B).grid(column=a_x + 1, row=a_y,
  545. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  546. tkinter.Button(top, bg=bbg, fg=fg, text='按列名排序', command=Stored_Column, font=FONT, width=width_B,
  547. height=height_B).grid(column=a_x + 2, row=a_y,
  548. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  549. global Sort_By, Ascending_Type, Ascending_New, Stored_BOX
  550. a_y += 1
  551. tkinter.Label(top, text='基准列(列号):', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,
  552. row=a_y) # 设置说明
  553. Sort_By = tkinter.Entry(top, width=width_B + 2)
  554. Sort_By.grid(column=a_x + 1, row=a_y, sticky=tkinter.W)
  555. tkinter.Button(top, bg=bbg, fg=fg, text='按数据排序', command=Stored_Value, font=FONT, width=width_B,
  556. height=height_B).grid(column=a_x + 2, row=a_y,
  557. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  558. a_y += 1
  559. Ascending_Type = tkinter.IntVar()
  560. Ascending_New = tkinter.IntVar()
  561. lable = ['正序排列', '倒序排列'] # 复选框
  562. for i in range(2):
  563. tkinter.Radiobutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text=lable[i],
  564. variable=Ascending_Type, value=i). \
  565. grid(column=a_x + i, row=a_y, sticky=tkinter.W)
  566. tkinter.Checkbutton(top, bg=bg, fg=fg, activebackground=bg, activeforeground=fg, selectcolor=bg, text='生成新表格',
  567. variable=Ascending_New).grid(column=a_x + 2, row=a_y, sticky=tkinter.W)
  568. a_y += 1
  569. Stored_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B * 4) # 显示符号
  570. Stored_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  571. a_y += 5
  572. tkinter.Button(top, bg=bbg, fg=fg, text='添加基准', command=add_Stored_Value, font=FONT, width=width_B,
  573. height=height_B).grid(column=a_x, row=a_y,
  574. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  575. tkinter.Button(top, bg=bbg, fg=fg, text='删除基准', command=Delete_Stored_Value, font=FONT, width=width_B,
  576. height=height_B).grid(column=a_x + 1, row=a_y,
  577. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  578. tkinter.Button(top, bg=bbg, fg=fg, text='打乱表格', command=Sample_Data, font=FONT, width=width_B,
  579. height=height_B).grid(column=a_x + 2, row=a_y,
  580. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  581. a_x += 3
  582. tkinter.Label(top, text='', bg=bg, fg=fg, font=FONT, width=1).grid(column=a_x, row=a_y) # 设置说明
  583. a_x += 1
  584. a_y = 0
  585. tkinter.Label(top, text='【机器学习】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  586. columnspan=3,
  587. row=a_y,
  588. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  589. global ML_BOX,ML_OUT
  590. a_y += 1
  591. ML_OUT = tkinter.StringVar()
  592. Put = tkinter.Entry(top, width=width_B * 2,textvariable = ML_OUT)
  593. Put.grid(column=a_x, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  594. Put['state'] = 'readonly'
  595. tkinter.Button(top, bg=bbg, fg=fg, text='选用学习器',command=set_Learner, font=FONT, width=width_B,height=height_B).grid(column=a_x+2, row=a_y, sticky=tkinter.E + tkinter.W)
  596. global Split_Input
  597. a_y += 1
  598. tkinter.Label(top, text='测试数据分割:', bg=bg, fg=fg, font=FONT, width=width_B, height=height_B).grid(column=a_x,row=a_y)
  599. Split_Input = tkinter.Entry(top, width=width_B * 2)
  600. Split_Input.grid(column=a_x + 1, row=a_y, columnspan=2, sticky=tkinter.E + tkinter.W)
  601. a_y += 1
  602. ML_BOX = tkinter.Listbox(top, width=width_B * 3, height=height_B*5)
  603. ML_BOX.grid(column=a_x, row=a_y, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  604. a_y += 5
  605. tkinter.Button(top, bg=bbg, fg=fg, text='导入学习器', command=Draw, font=FONT, width=width_B,height=height_B).grid(column=a_x, row=a_y,
  606. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  607. tkinter.Button(top, bg=bbg, fg=fg, text='查看数据', command=Show_Args, font=FONT, width=width_B,height=height_B).grid(column=a_x + 1, row=a_y,
  608. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  609. tkinter.Button(top, bg=bbg, fg=fg, text='删除学习器', command=Del_Leaner, font=FONT, width=width_B,height=height_B).grid(column=a_x + 2, row=a_y,
  610. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  611. a_y += 1
  612. tkinter.Button(top, bg=bbg, fg=fg, text='训练机器', command=Fit_Learner, font=FONT, width=width_B,height=height_B).grid(column=a_x, row=a_y,
  613. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  614. tkinter.Button(top, bg=bbg, fg=fg, text='测试机器', command=Score_Learner, font=FONT, width=width_B,height=height_B).grid(column=a_x + 1, row=a_y,
  615. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  616. tkinter.Button(top, bg=bbg, fg=fg, text='数据预测', command=Predict_Learner, font=FONT, width=width_B,height=height_B).grid(column=a_x + 2, row=a_y,
  617. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  618. a_y += 1
  619. tkinter.Label(top, text='【学习器选择和配置】', bg=bg, fg=fg, font=FONT, width=width_B * 3, height=height_B).grid(column=a_x,
  620. columnspan=3,
  621. row=a_y,
  622. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N) # 设置说明
  623. a_y += 1
  624. tkinter.Button(top, bg=bbg, fg=fg, text='线性回归', command=Add_Line, font=FONT, width=width_B,height=height_B).grid(column=a_x, row=a_y,
  625. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  626. tkinter.Button(top, bg=bbg, fg=fg, text='岭回归', command=Add_Ridge, font=FONT, width=width_B,height=height_B).grid(column=a_x + 1, row=a_y,
  627. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  628. tkinter.Button(top, bg=bbg, fg=fg, text='Lasso', command=Add_Lasso, font=FONT, width=width_B,height=height_B).grid(column=a_x + 2, row=a_y,
  629. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  630. a_y += 1
  631. tkinter.Button(top, bg=bbg, fg=fg, text='逻辑回归', command=Add_LogisticRegression, font=FONT, width=width_B,height=height_B).grid(column=a_x, row=a_y,
  632. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  633. tkinter.Button(top, bg=bbg, fg=fg, text='决策树', command=ML_Sorry, font=FONT, width=width_B,height=height_B).grid(column=a_x + 1, row=a_y,
  634. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  635. tkinter.Button(top, bg=bbg, fg=fg, text='SVM', command=ML_Sorry, font=FONT, width=width_B,height=height_B).grid(column=a_x + 2, row=a_y,
  636. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  637. a_y += 1
  638. tkinter.Button(top, bg=bbg, fg=fg, text='朴素贝叶斯', command=ML_Sorry, font=FONT, width=width_B,height=height_B).grid(column=a_x, row=a_y,
  639. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  640. tkinter.Button(top, bg=bbg, fg=fg, text='K邻近分类', command=Add_Knn, font=FONT, width=width_B,height=height_B).grid(column=a_x + 1, row=a_y,
  641. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  642. tkinter.Button(top, bg=bbg, fg=fg, text='K邻近预测', command=Add_Knn_Class, font=FONT, width=width_B,height=height_B).grid(column=a_x + 2, row=a_y,
  643. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N)
  644. global Args_Learner
  645. a_y += 1
  646. Args_Learner = tkinter.Text(top, width=width_B * 3, height=height_B * 11)
  647. Args_Learner.grid(column=a_x, row=a_y, columnspan=3, rowspan=11, sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S)
  648. top.mainloop()
  649. def Show_Help():
  650. tkinter.messagebox.showinfo('使用提示', Args_Help)
  651. def ML_Sorry():
  652. tkinter.messagebox.showinfo('非常抱歉', '高级别的机器学习请到机器学习板块深入研究...')
  653. def Tra_RDic():
  654. ML.Tra_RDic()
  655. Update_R_BOX()
  656. def Del_Sheet():
  657. name = get_Name()
  658. ML.Del_Form(name)
  659. Updat_BOX()
  660. def Del_Leaner():
  661. Learn = get_Learner(True)
  662. set_Learne = get_Learner(False)#获取学习器Learner
  663. if set_Learne != Learn:
  664. ML.Del_Leaner(Learn)
  665. Update_Leaner()
  666. def Show_Args():
  667. learner = get_Learner(True)
  668. new = tkinter.messagebox.askokcancel('提示', f'是否将数据生成表格。\n(可绘制成散点图对比数据)')
  669. print(new)
  670. Data = ML.Show_Args(learner,new)
  671. title = f'CoTan数据处理 查看数据:{learner}'
  672. Creat_TextSheet(f'对象:{learner}\n\n{Data[0]}\n\n\n{Data[1]}', title)
  673. Updat_BOX()
  674. def get_Args_Learner():
  675. global Args_Learner
  676. return Args_Learner.get('0.0',tkinter.END)
  677. def Score_Learner():
  678. name = get_Name()#表格数据
  679. learner = get_Learner()
  680. try:
  681. split = float(Split_Input.get())
  682. if split < 0 or 1 < split:raise Exception
  683. except:split = 0.3
  684. socore = ML.Fit(name,learner,Score_Only=True,split=split)[1]
  685. tkinter.messagebox.showinfo('测试完成', f'针对测试数据评分结果为:{socore}')
  686. def Predict_Learner():
  687. name = get_Name()#表格数据
  688. learner = get_Learner()
  689. Data = ML.Predict(name,learner)
  690. title = f'CoTan数据处理 表格:{name} 学习器:{learner}'
  691. Creat_TextSheet(Data, title)
  692. Updat_BOX()
  693. def Fit_Learner():
  694. name = get_Name()#表格数据
  695. learner = get_Learner()
  696. try:
  697. split = float(Split_Input.get())
  698. if split < 0 or 1 < split:raise Exception
  699. except:split = 0.3
  700. socore = ML.Fit(name,learner,Text=get_Args_Learner(),split=split)
  701. tkinter.messagebox.showinfo('训练完成', f'针对训练数据({(1-split)*100}%)评分结果为:{socore[0]}\n'
  702. f'针对测试数据评分({split*100}%)结果为:{socore[1]}')
  703. def set_Learner():
  704. global ML_OUT
  705. ML_OUT.set(get_Learner(True))
  706. def get_Learner(Type=False):
  707. global Learn_Dic,ML_BOX,ML_OUT
  708. if Type:
  709. try:
  710. return list(Learn_Dic.keys())[ML_BOX.curselection()[0]]
  711. except:
  712. # raise
  713. try:
  714. return list(Learn_Dic.keys)[0]
  715. except:
  716. return None
  717. else:
  718. try:
  719. return ML_OUT.get()
  720. except:
  721. return None
  722. def Add_Knn_Class():
  723. Add_leaner('Knn_class')
  724. def Add_LogisticRegression():
  725. Add_leaner('LogisticRegression')
  726. def Add_Lasso():
  727. Add_leaner('Lasso')
  728. def Add_Knn():
  729. Add_leaner('Knn')
  730. def Add_Ridge():
  731. Add_leaner('Ridge')
  732. def Add_Line():
  733. Add_leaner('Line')
  734. def Add_leaner(Type):#添加Lenear的核心
  735. ML.Add_Learner(Type,Text=get_Args_Learner())
  736. Update_Leaner()
  737. def Update_Leaner():
  738. global Learn_Dic,ML_BOX
  739. Learn_Dic = ML.Return_Learner()
  740. ML_BOX.delete(0,tkinter.END)
  741. ML_BOX.insert(tkinter.END,*Learn_Dic.keys())
  742. def DecisionTreeClassifier():
  743. name = get_Name()
  744. ML.DecisionTreeClassifier(name)
  745. Updat_BOX()
  746. def Replace_Index():
  747. global replace_Dic, Repalce_RC, ML
  748. name = get_Name()
  749. Dic = eval(replace_Dic.get())
  750. is_Column = bool(Repalce_RC.get()) # 操作行-False,操作列-True
  751. save = bool(RC_Type[0].get())
  752. ML.Replace_Index(name, is_Column, Dic, save)
  753. Updat_BOX()
  754. def Change_Index():
  755. global Repalce_RC, replace_iloc, RC_Type, ML
  756. name = get_Name() # 名字
  757. is_Column = bool(Repalce_RC.get()) # 操作行名-False,操作列名-True
  758. iloc = int(replace_iloc.get()) # 替换的列号(行号)
  759. save = bool(RC_Type[0].get())
  760. drop = not bool(RC_Type[1].get())
  761. ML.Change_Index(name, is_Column, iloc, save, drop)
  762. Updat_BOX()
  763. def num_toName():
  764. global Repalce_RC, replace_iloc, RC_Type, ML
  765. name = get_Name() # 名字
  766. is_Column = bool(Repalce_RC.get()) # 操作行名-False,操作列名-True
  767. save = bool(RC_Type[0].get())
  768. ML.num_toName(name, is_Column, save)
  769. Updat_BOX()
  770. def num_withName():
  771. global Repalce_RC, RC_Type, ML
  772. name = get_Name() # 名字
  773. is_Column = bool(Repalce_RC.get()) # 操作行名-False,操作列名-True
  774. save = bool(RC_Type[0].get())
  775. ML.num_withName(name, is_Column, save)
  776. Updat_BOX()
  777. def DateTime_Index(is_Date=True):
  778. global Repalce_RC, RC_Type, ML, Date_Input, Date_Type
  779. name = get_Name() # 名字
  780. is_Column = bool(Repalce_RC.get()) # 操作行名-False,操作列名-True
  781. save = bool(RC_Type[0].get())
  782. k = ['start', 'end', 'freq']
  783. Init = {}
  784. for i in range(len(Date_Input)):
  785. Input = Date_Input[i].get()
  786. if Input == '': continue
  787. Init[k[i]] = Input
  788. if len(Init) == 3:
  789. if bool(Date_Type.get()): # 使用间隔
  790. del Init['end']
  791. else:
  792. del Init['freq']
  793. if is_Date:
  794. ML.Date_Index(name, is_Column, save, **Init)
  795. else:
  796. ML.Time_Index(name, is_Column, save, **Init)
  797. Updat_BOX()
  798. def Date_Index():
  799. DateTime_Index(True)
  800. def Time_index():
  801. DateTime_Index(False)
  802. def DTYPE():
  803. global Dtype_Column, Dtype_Input, Dtype_Wrong, Dtype_Func, ML
  804. type_ = bool(Dtype_Func.get())
  805. name = get_Name()
  806. column_list = Dtype_Column.get().split(',')
  807. if column_list == ['']: column_list = []
  808. dtype = Dtype_Input.get()
  809. wrong = Dtype_Wrong.get()
  810. if type_: # 软转换
  811. if wrong != 'ignore': wrong = 'coerce'
  812. ML.Reasonable_Type(name, column_list, dtype, wrong)
  813. else:
  814. ML.as_Type(name, column_list, dtype, 'ignore')
  815. Updat_BOX()
  816. def Import_c(): # 导入绘制方法
  817. global Done_Func
  818. Dic = askopenfilename(title='打开Python脚本', filetypes=[("Python", ".py"), ("TXT", ".txt")])
  819. with open(Dic) as f:
  820. get = f.read()
  821. Render_ToHTML(ML.Import_c(get), '自定义图')
  822. def get_ARGS(): # 获取画图的args
  823. global Args_Input
  824. return Args_Input.get('0.0', tkinter.END)
  825. def Draw():
  826. global R_Dic, R_BOX
  827. Dic = asksaveasfilename(title='选择渲染保存地址', filetypes=[("HTML", ".html")])
  828. if Dic == '': return False
  829. try:
  830. if Dic[-5:] != '.html': raise Exception
  831. except:
  832. Dic += '.html'
  833. webbrowser.open(ML.Draw_Page(get_ARGS(), Dic))
  834. Update_R_BOX()
  835. def Draw_One():
  836. global R_Dic, R_BOX
  837. Dic = asksaveasfilename(title='选择渲染保存地址', filetypes=[("HTML", ".html")])
  838. if Dic == '': return False
  839. try:
  840. if Dic[-5:] != '.html': raise Exception
  841. except:
  842. Dic += '.html'
  843. list(R_Dic.values())[R_BOX.curselection()[0]].render(Dic)
  844. webbrowser.open(Dic)
  845. Update_R_BOX()
  846. def to_OverLap():
  847. global ML, Over_Up, Over_Down
  848. if Over_Down != None and Over_Up != None:
  849. try:
  850. Render_ToHTML(ML.Overlap(Over_Down, Over_Up), f'合成图')
  851. except:
  852. raise
  853. Over_Down = None
  854. Over_Up = None
  855. Update_Over_Box()
  856. def Update_Over_Box():
  857. global Over_BOX, Over_Down, Over_Up
  858. Over_BOX.delete(0, tkinter.END)
  859. if Over_Down != None:
  860. Over_BOX.insert(tkinter.END, f'底图: {Over_Down}')
  861. if Over_Up != None:
  862. Over_BOX.insert(tkinter.END, f'顶图: {Over_Up}')
  863. def Over_Down_Add():
  864. global Over_Down
  865. Over_Down = list(R_Dic.keys())[R_BOX.curselection()[0]]
  866. Update_Over_Box()
  867. def Over_UP_Add():
  868. global Over_Up
  869. Over_Up = list(R_Dic.keys())[R_BOX.curselection()[0]]
  870. Update_Over_Box()
  871. def Del_R_BOX():
  872. global R_Dic, R_BOX, ML
  873. key = list(R_Dic.keys())[R_BOX.curselection()[0]]
  874. ML.Delete_RDic(key)
  875. Update_R_BOX()
  876. def Update_R_BOX():
  877. global R_Dic, R_BOX, ML
  878. R_Dic = ML.retunr_RDic()
  879. R_BOX.delete(0, tkinter.END)
  880. R_BOX.insert(tkinter.END, *R_Dic.keys())
  881. def Render_ToHTML(c, name):
  882. global R_Dic, Draw_asWell
  883. if bool(Draw_asWell.get()):
  884. c.render(f'{PATH}\\{name}.html')
  885. Update_R_BOX()
  886. def to_Geo():
  887. global ML
  888. name = get_Name()
  889. Render_ToHTML(ML.to_Geo(name, get_ARGS()), 'Geo地图')
  890. def to_Map():
  891. global ML
  892. name = get_Name()
  893. Render_ToHTML(ML.to_Map(name, get_ARGS()), 'Map地图')
  894. def to_ScatterGeo():
  895. global ML
  896. name = get_Name()
  897. Render_ToHTML(ML.to_ScatterGeo(name, get_ARGS()), 'Geo点地图')
  898. def to_TreeMap():
  899. global ML
  900. name = get_Name()
  901. Render_ToHTML(ML.to_TreeMap(name, get_ARGS()), '矩形树图')
  902. def to_Tree():
  903. global ML
  904. name = get_Name()
  905. Render_ToHTML(ML.to_Tree(name, get_ARGS()), '树状图')
  906. def to_Sankey():
  907. global ML
  908. name = get_Name()
  909. Render_ToHTML(ML.to_Sankey(name, get_ARGS()), '桑基图')
  910. def to_Sunburst():
  911. global ML
  912. name = get_Name()
  913. Render_ToHTML(ML.to_Sunburst(name, get_ARGS()), '旭日图')
  914. def to_ThemeRiver():
  915. global ML
  916. name = get_Name()
  917. Render_ToHTML(ML.to_ThemeRiver(name, get_ARGS()), '河流图')
  918. def to_Calendar():
  919. global ML
  920. name = get_Name()
  921. Render_ToHTML(ML.to_Calendar(name, get_ARGS()), '日历图')
  922. def to_Gauge():
  923. global ML
  924. name = get_Name()
  925. Render_ToHTML(ML.to_Gauge(name, get_ARGS()), '仪表图')
  926. def to_Liquid():
  927. global ML
  928. name = get_Name()
  929. Render_ToHTML(ML.to_Liquid(name, get_ARGS()), '水球图')
  930. def to_Line3D():
  931. global ML
  932. name = get_Name()
  933. Render_ToHTML(ML.to_Line3D(name, get_ARGS()), '3D折线图')
  934. def to_Scatter3D():
  935. global ML
  936. name = get_Name()
  937. Render_ToHTML(ML.to_Scatter3D(name, get_ARGS()), '3D散点图')
  938. def to_Bar3d():
  939. global ML
  940. name = get_Name()
  941. Render_ToHTML(ML.to_Bar3d(name, get_ARGS()), '3D柱状图')
  942. def to_WordCloud():
  943. global ML
  944. name = get_Name()
  945. Render_ToHTML(ML.to_WordCloud(name, get_ARGS()), '词云图')
  946. def to_Radar():
  947. global ML
  948. name = get_Name()
  949. Render_ToHTML(ML.to_Radar(name, get_ARGS()), '雷达图')
  950. def to_Polar():
  951. global ML
  952. name = get_Name()
  953. Render_ToHTML(ML.to_Polar(name, get_ARGS()), '极坐标图')
  954. def to_Pie():
  955. global ML
  956. name = get_Name()
  957. Render_ToHTML(ML.to_Pie(name, get_ARGS()), '饼图')
  958. def to_Parallel():
  959. global ML
  960. name = get_Name()
  961. Render_ToHTML(ML.to_Parallel(name, get_ARGS()), '多轴图')
  962. def to_XY_Graph():
  963. global ML
  964. name = get_Name()
  965. Render_ToHTML(ML.to_XY_Graph(name, get_ARGS()), '关系图')
  966. def to_Graph():
  967. global ML
  968. name = get_Name()
  969. Render_ToHTML(ML.to_Graph(name, get_ARGS()), '关系图')
  970. def to_Funnel():
  971. global ML
  972. name = get_Name()
  973. Render_ToHTML(ML.to_Funnel(name, get_ARGS()), '漏斗图')
  974. def to_HeatMap():
  975. global ML
  976. name = get_Name()
  977. Render_ToHTML(ML.to_HeatMap(name, get_ARGS()), '热力图')
  978. def to_Boxpolt():
  979. global ML
  980. name = get_Name()
  981. Render_ToHTML(ML.to_Boxpolt(name, get_ARGS()), '箱形图')
  982. def to_Pictorialbar():
  983. global ML
  984. name = get_Name()
  985. Render_ToHTML(ML.to_Pictorialbar(name, get_ARGS()), '象形柱状图')
  986. def to_Scatter():
  987. global ML
  988. name = get_Name()
  989. Render_ToHTML(ML.to_Scatter(name, get_ARGS()), '散点图')
  990. def to_Line():
  991. global ML
  992. name = get_Name()
  993. Render_ToHTML(ML.to_Line(name, get_ARGS()), '折线图')
  994. def to_Bar():
  995. global ML
  996. name = get_Name()
  997. Render_ToHTML(ML.to_Bar(name, get_ARGS()), '柱状图')
  998. def Show_Help():
  999. tkinter.messagebox.showinfo('帮助字典', Clean_Help)
  1000. def Open_Python():
  1001. global Done_Func
  1002. Dic = askopenfilename(title='打开Python脚本', filetypes=[("Python", ".py"), ("TXT", ".txt")])
  1003. with open(Dic) as f:
  1004. get = f.read()
  1005. Done_Func.delete('0.0', tkinter.END)
  1006. Done_Func.insert('0.0', get)
  1007. def get_InsertClean_Text():
  1008. global Done_Func, Clean_Text
  1009. Done_Func.delete('0.0', tkinter.END)
  1010. Done_Func.insert('0.0', Clean_Text)
  1011. def get_CleanEXP():
  1012. global ML, Clean_List, Done_CleanBox, Done_Func
  1013. name = Clean_List[Done_CleanBox.curselection()[0]]
  1014. get = ML.Return_CleanExp(name)
  1015. Done_Func.delete('0.0', tkinter.END)
  1016. Done_Func.insert('0.0', get)
  1017. def Tra_Clean():
  1018. global ML
  1019. ML.Tra_Clean()
  1020. Updat_BOX()
  1021. def Done_Clean():
  1022. global ML
  1023. name = get_Name()
  1024. Data = ML.Done_CleanFunc(name)
  1025. title = f'CoTan数据处理 表格:{name}.数据清洗'
  1026. Creat_TextSheet(Data, title)
  1027. Updat_BOX()
  1028. def Del_Clean():
  1029. global ML, Clean_List, Done_CleanBox
  1030. name = Clean_List[Done_CleanBox.curselection()[0]]
  1031. ML.Delete_CleanFunc(name)
  1032. Update_Clean()
  1033. def Update_Clean():
  1034. global ML, Done_CleanBox, Clean_List
  1035. Clean_List = ML.Return_CleanFunc()
  1036. Done_CleanBox.delete(0, tkinter.END)
  1037. Done_CleanBox.insert(tkinter.END, *Clean_List)
  1038. def Add_Clean():
  1039. global ML, Done_CleanBox, Done_Func
  1040. Exp = Done_Func.get('0.0', tkinter.END)
  1041. print(Exp)
  1042. ML.Add_CleanFunc(Exp)
  1043. Update_Clean()
  1044. def Done_NaN():
  1045. global Drop_Column
  1046. name = get_Name()
  1047. Data = ML.Dropna(name, True)
  1048. title = f'CoTan数据处理 表格:{name}.NaN'
  1049. Creat_TextSheet(Data, title)
  1050. Updat_BOX()
  1051. def is_Na():
  1052. global Bool_E
  1053. name = get_Name()
  1054. Data = ML.is_Na(name)
  1055. title = f'CoTan数据处理 表格:{name}.NaN'
  1056. Creat_TextSheet(Data, title)
  1057. Updat_BOX()
  1058. def Make_BoolSheet():
  1059. global Bool_E
  1060. Bool_Exp = Bool_E.get()
  1061. name = get_Name()
  1062. Data = ML.Done_Bool(name, Bool_Exp, True)
  1063. print(Data)
  1064. title = f'CoTan数据处理 表格:{name} 布尔化'
  1065. Creat_TextSheet(Data, title)
  1066. Updat_BOX()
  1067. def Del_Data():
  1068. global Slice_new, Column_clist, Row_clist
  1069. Column = Column_clist[0].get().replace(' ', '').split(',')
  1070. Row = Row_clist[0].get().replace(' ', '').split(',')
  1071. print(Column)
  1072. new = bool(Slice_new.get())
  1073. name = get_Name()
  1074. try:
  1075. Data = ML.Delete(name, Column, Row, new)
  1076. except:
  1077. Data = 'None 你的操作不被允许'
  1078. title = f'CoTan数据处理 表格:{name}'
  1079. Creat_TextSheet(Data, title)
  1080. Updat_BOX()
  1081. def __get_clist(n, t=str):
  1082. a = []
  1083. for i in n:
  1084. b = i.get().replace(' ', '')
  1085. if b == '':
  1086. a.append(None)
  1087. else:
  1088. try:
  1089. a.append(t(b))
  1090. except:
  1091. a.append(None)
  1092. if a[0] != None and a[1] == None:
  1093. a[1] = a[0] + 1
  1094. a[2] = None
  1095. return a
  1096. def Slice_Data():
  1097. global Slice_new, Column_Type, Row_Type, Column_clist, Row_clist
  1098. CT = Column_Type.get()
  1099. U = True
  1100. if CT == 0: # 输入的列号
  1101. Column = slice(*__get_clist(Column_clist, int))
  1102. elif CT == 1:
  1103. U = False
  1104. Column = slice(*__get_clist(Column_clist, str))
  1105. else:
  1106. get = Column_clist[0].get().replace(' ', '').split(',')
  1107. Column = []
  1108. for i in get:
  1109. try:
  1110. Column.append(int(i))
  1111. except:
  1112. pass
  1113. RT = Row_Type.get()
  1114. if RT == 0: # 输入的列号
  1115. Row = slice(*__get_clist(Row_clist, int))
  1116. elif RT == 1:
  1117. Row = slice(*__get_clist(Row_clist, str))
  1118. else:
  1119. get = Row_clist[0].get().replace(' ', '').split(',')
  1120. Row = []
  1121. for i in get:
  1122. try:
  1123. Row.append(int(i))
  1124. except:
  1125. pass
  1126. new = bool(Slice_new.get())
  1127. name = get_Name()
  1128. try:
  1129. Data = ML.get_Clice(name, Column, Row, U, new)
  1130. except:
  1131. Data = 'None 你的操作不被允许'
  1132. title = f'CoTan数据处理 表格:{name}'
  1133. Creat_TextSheet(Data, title)
  1134. Updat_BOX()
  1135. def Sample_Data():
  1136. global ML,Ascending_New
  1137. name = get_Name()
  1138. new = bool(Ascending_New.get())
  1139. Data = ML.Sample(name, new)
  1140. title = f'CoTan数据处理 打乱表格:{name}'
  1141. Creat_TextSheet(Data, title)
  1142. Updat_BOX()
  1143. def Stored_Value():
  1144. global ML, Stored_List,Ascending_New
  1145. name = get_Name()
  1146. new = bool(Ascending_New.get())
  1147. Data = ML.Stored_Valuse(name, Stored_List, new)
  1148. title = f'CoTan数据处理 表格:{name}.Stored'
  1149. Creat_TextSheet(Data, title)
  1150. Updat_BOX()
  1151. def Tra_Stored_Value():
  1152. global Stored_List, Stored_BOX
  1153. Stored_List = []
  1154. Update_Stored()
  1155. def Delete_Stored_Value():
  1156. global Stored_List, Stored_BOX, Ascending_Type
  1157. del Stored_List[Stored_BOX.curselection()[0]]
  1158. Update_Stored()
  1159. def add_Stored_Value(): # 按基准列排行
  1160. global ML, Stored_List, Sort_By, Ascending_Type
  1161. try:
  1162. a = not bool(Ascending_Type.get())
  1163. value = int(Sort_By.get())
  1164. Stored_List.append((value, a))
  1165. except:
  1166. pass
  1167. Update_Stored()
  1168. def Update_Stored():
  1169. global Stored_List, Stored_BOX
  1170. re = []
  1171. d = {True: '正序', False: '倒叙'}
  1172. for i in Stored_List:
  1173. re.append(f"列号:{i[0]}, 排序方式{d[i[1]]}")
  1174. Stored_BOX.delete(0, tkinter.END)
  1175. Stored_BOX.insert(tkinter.END, *re)
  1176. def Stored_Column(): # 行
  1177. global ML
  1178. name = get_Name()
  1179. a = not bool(Ascending_Type.get())
  1180. new = bool(Ascending_New.get())
  1181. Data = ML.Sorted(name, False, new, a)
  1182. title = f'CoTan数据处理 表格:{name}.Stored by Column'
  1183. Creat_TextSheet(Data, title)
  1184. Updat_BOX()
  1185. def Stored_Row(): # 行
  1186. global ML
  1187. name = get_Name()
  1188. new = bool(Ascending_New.get())
  1189. a = not bool(Ascending_Type.get())
  1190. Data = ML.Sorted(name, True, new, a)
  1191. title = f'CoTan数据处理 表格:{name}.Stored by Row'
  1192. Creat_TextSheet(Data, title)
  1193. Updat_BOX()
  1194. def T():
  1195. global ML
  1196. name = get_Name()
  1197. new = bool(Ascending_New.get())
  1198. Data = ML.T(name, new)
  1199. title = f'CoTan数据处理 表格:{name}.T'
  1200. Creat_TextSheet(Data, title)
  1201. Updat_BOX()
  1202. def Show_Des():
  1203. global PATH, top
  1204. if not tkinter.messagebox.askokcancel('提示', f'是否统计数据,大量的数据需要耗费一定的时间(确定后,系统会在后台统计)'): return False
  1205. Dic = f'{PATH}/$Show_Des_Sheet.html'
  1206. try:
  1207. name = get_Name()
  1208. if name == None: raise Exception
  1209. ML.to_Report(name, Dic)
  1210. webbrowser.open(Dic)
  1211. except:
  1212. pass
  1213. def Show_describe():
  1214. global ML, Des_Bool
  1215. Des = bool(Des_Bool.get())
  1216. name = get_Name()
  1217. title = f'CoTan数据处理 表格:{name}_describe'
  1218. Data = str(ML.Describe(name, Des))
  1219. Creat_TextSheet(Data, title)
  1220. Updat_BOX()
  1221. def Write_Sheet():
  1222. global ML, top
  1223. name = get_Name()
  1224. title = f'CoTan数据处理 表格:{name}'
  1225. Data = str(ML.get_Sheet(name))
  1226. Creat_TextSheet(Data, title)
  1227. def Creat_TextSheet(data, name):
  1228. global bg, ft1
  1229. new_top = tkinter.Toplevel(bg=bg)
  1230. new_top.title(name)
  1231. new_top.geometry('+10+10') # 设置所在位置
  1232. text = ScrolledText(new_top, font=ft1, height=50)
  1233. text.pack(fill=tkinter.BOTH)
  1234. text.insert('0.0', data)
  1235. text.config(state=tkinter.DISABLED)
  1236. new_top.resizable(width=False, height=False)
  1237. def get_Column(): # 列名(横行竖列,列名是上面的)
  1238. global ML
  1239. name = get_Name()
  1240. Updat_IndexBOX(ML.get_Column(name))
  1241. def get_Index(): # 行名(横行竖列,行名左)
  1242. global ML
  1243. name = get_Name()
  1244. Updat_IndexBOX(ML.get_Index(name))
  1245. def Updat_IndexBOX(get_Index):
  1246. global top, Index_BOX
  1247. Index_BOX.delete(0, tkinter.END)
  1248. Index_BOX.insert(tkinter.END, *get_Index)
  1249. def Show_One():
  1250. global PATH, to_HTML_Type
  1251. Dic = f'{PATH}/$Show_Sheet.html'
  1252. try:
  1253. name = get_Name()
  1254. if name == None: raise Exception
  1255. ML.to_Html_One(name, Dic)
  1256. webbrowser.open(Dic)
  1257. except:
  1258. # pass
  1259. raise
  1260. def Show():
  1261. global PATH, to_HTML_Type
  1262. Dic = f'{PATH}/$Show_Sheet.html'
  1263. try:
  1264. name = get_Name()
  1265. if name == None: raise Exception
  1266. ML.to_Html(name, Dic, to_HTML_Type.get())
  1267. webbrowser.open(Dic)
  1268. except:
  1269. pass
  1270. def to_CSV():
  1271. global top, Seq_Input, Code_Input, str_must, Index_must
  1272. Dic = asksaveasfilename(title='选择保存的CSV', filetypes=[("CSV", ".csv")])
  1273. Seq = Seq_Input.get()
  1274. name = get_Name()
  1275. ML.to_CSV(name,Dic,Seq)
  1276. Updat_BOX()
  1277. def Add_CSV():
  1278. global top, Seq_Input, Code_Input, str_must, Index_must,name_Input
  1279. Dic = askopenfilename(title='选择载入的CSV', filetypes=[("CSV", ".csv")])
  1280. if Dic == '':return False
  1281. Seq = Seq_Input.get()
  1282. Codeing = Code_Input.get()
  1283. str_ = bool(str_must.get())
  1284. Index = bool(Index_must.get())
  1285. name = name_Input.get().replace(' ','')
  1286. if name == '':
  1287. name = os.path.splitext(os.path.split(Dic)[1])[0]
  1288. print(name)
  1289. if Codeing == '':
  1290. with open(Dic, 'rb') as f:
  1291. Codeing = chardet.detect(f.read())['encoding']
  1292. if Seq == '': Seq = ','
  1293. ML.Add_CSV(Dic, name, Seq, Codeing, str_, Index)
  1294. Updat_BOX()
  1295. def Add_Python():
  1296. global top, Seq_Input, Code_Input, str_must, Index_must
  1297. Dic = askopenfilename(title='选择载入的py', filetypes=[("Python", ".py"), ("Txt", ".txt")])
  1298. name = name_Input.get().replace(' ','')
  1299. if name == '':
  1300. name = os.path.splitext(os.path.split(Dic)[1])[0]
  1301. with open(Dic, 'r') as f:
  1302. ML.Add_Python(f.read(), name)
  1303. Updat_BOX()
  1304. def get_Name(): # 获得名字统一接口
  1305. global Form_List
  1306. try:
  1307. return Form_List[Form_BOX.curselection()[0]]
  1308. except:
  1309. try:
  1310. return Form_List[0]
  1311. except:
  1312. return None
  1313. def Updat_BOX():
  1314. global top, Form_BOX, Form_List
  1315. Form_List = ML.get_FormList()
  1316. Form_BOX.delete(0, tkinter.END)
  1317. Form_BOX.insert(tkinter.END, *Form_List)