def dtbl2xls(dtbl, xls='a.xlsx'): # Schlussel muss "blatt/position" sein wb = xl.load_workbook(xls) ### HAUPT ### for sh, tbl in dtbl.items(): sh = sh.split('/') # blatt/position if len(sh) == 1: sh = sh[0] pos = 'A1' elif len(sh) > 1: pos = sh[1] sh = sh[0] ws = wb[sh] pos = cell2pos(pos) xi = pos[0] yj = pos[1] tbl = xz.bless(tbl) # for i, lis in enumerate(tbl): i2 = i + xi i2 = i + yj for j, x in enumerate(lis): j2 = j + yj j2 = j + xi # fmt = ws.cell(row=i2,column=j2).style ws.cell(row=i2, column=j2).value = x ### AUSGABE ### wb.save(xls) if notice == False: sys.stdout.write("Ausgabe als %s \n" % ex)
def show2str(res, fmt='psql'): import tabulate """ https://pypi.org/project/tabulate/ plain/simple/github/grid/fancy_grid/pipe/ orgtbl/jira/presto/psql/rst/mediawiki/moinmoin/ youtrack/html/ latex/latex_raw/latex_booktabs/textile/ orgtbl is the basic """ for i in range(len(res)): for j in range(len(res[0])): x = res[i][j] x = xz.bless(x) x = value4show(x) res[i][j] = x fmt = 'github' fmt = 'psql' # Das ist das hochst @ 2020-02-09 res = tabulate.tabulate(res, headers="firstrow", tablefmt=fmt) # print( type(res) ) #d -> str if fmt == 'psql': res = res.split("\n") res.append(res[1]) res.append(res[0]) res = "\n".join(res) return res
def thiscrosstable(sache): import crosstable sache = xz.str2tbl(sache) sache = xz.bless(sache) sache = transpose(sache) sache = crosstable.crosstable(sache[0], sache[1], sache[2]) tmp = [] for lis in sache: lis = [str(x) for x in lis] tmp.append(lis) sache = tmp sache = transpose(sache) sache = ["\t".join(lis) for lis in sache] return sache
def belt2sum(sache): sache = xz.str2tbl(sache) sache = xz.bless(sache) res = {} for lis in sache: k = lis[0] v = int(lis[1]) if not k in res: res[k] = 0 res[k] += v # sache = '' for k in sorted(res.keys()): sache += "%s\t%d\n" % (k, res[k]) # sache += "<SUM>\t%d\n" % sum(res.values()) return sache
def tbl4log(txt, dic, gettable=False): assert (isinstance(dic, dict)) tbl = xz.txt2tbl(txt) header = xz.getheader(txt) # if not 'tag' in dic: dic['tag'] = xt.heute() # assert sorted(header) == sorted(list(dic.keys())) if tbl[-1][0] == str(dic['tag']): tbl.pop() res = [dic[k] for k in header] tbl.append(res) # xz.tbl2txt(tbl, txt) if gettable == True: return tbl else: tbl = xz.txt2ldic(txt) tbl = xz.bless(tbl) return tbl, header
def nv2qt(nv, fjahr=1): tbl = nv2mt(nv, fjahr) res = [] for lis in tbl: if lis[0] == '/': tmp = ['/', 'Q1', 'Q2', 'Q3', 'Q4'] else: j = lis.pop(0) tmp = [] tmp.append(sum(lis[0:3])) tmp.append(sum(lis[3:6])) tmp.append(sum(lis[6:9])) tmp.append(sum(lis[9:12])) tmp.insert(0, j) res.append(tmp) return res # ##### DIREKT ############### if __name__ == '__main__': nv = xz.txt2dic(labomi + 'a.tsv') nv = xz.bless(nv) tbl = nv2mt(nv, 12) xz.show(tbl) tbl = nv2qt(nv, 12) xz.show(tbl) kbench.enfin()
def istzr(tbl): mode = 'n' ### X : ZEIT ### lis = tbl[0].copy() lis = xz.bless(lis) lis.pop(0) i = lis.pop(0) # if 'Q' in str(i): mode = 'q' elif i < 3000: mode = 'j' elif i >= 198001 and i <= 300000: mode = 'n' ## Typ Jahren ## if mode == 'j': for x in lis: if x - i == 1: i = x continue return False ## Typ Quartal ## elif mode == 'q': i = int(i[0:4]) for x in lis: if not 'Q': return False if not len(x) == 6: return False if not x[4] == 'Q': return False # j = int(x[0:4]) q = int(x[5]) if not q in [1, 2, 3, 4]: return False if q == 1: if not j - i == 1: return False else: if not j == i: return False i = j ## Typ IntMonat ## elif mode == 'n': for x in lis: # print( x, x-i,x % 100 ) #d if x - i == 1: i = x continue elif x % 100 == 1 and x - i == 89: i = x continue return False ### Y : KOLONNE ### lis = [x[0] for x in tbl] lis.pop(0) tmp = lis.copy() tmp = uniq(tmp) lis.sort() tmp.sort() if lis == tmp: return True else: return False
print( res.xs ) print( res.ys ) print( '*'*50 ) return res """ # ##### DIREKT ############### if __name__ == '__main__': mode = 2 if mode == 1: txt = 'a.tsv' tbl = xz.txt2tbl(txt) tbl = transpose(tbl) tbl = xz.bless(tbl) tbl = crosstable(tbl[0], tbl[1], tbl[2]) # tbl = crosstable(tbl[0],tbl[1],[]) xz.show(tbl) xz.tbl2txt(tbl, 'b.tsv') # elif mode == 2: tbl = xz.txt2tbl('a.tsv') tbl = xz.bless(tbl) tbl = tbl2xdic(tbl) # sym = 'm2oq' sym = 'm2oj' tbl = tbl.aggrtyp(sym) tbl.to_txt('b.tsv') print(tbl.sum())