我想将这些打印的“ ex2”表保存为具有不同名称的excel。这将打印3个不同的表,我需要将这些表保存在三个不同的excel文件中。我试图以这种方式
b= [{'A': (1.9047619047619044, 1.9047619047619047),
'B': (0.9523809523809522, 0.9523809523809523),
'C': (2.857142857142857, 2.857142857142857),
'D': (1.4285714285714286, 1.4285714285714286),
'E': (1.9047619047619044, 1.9047619047619047),
'K': (3.809523809523809, 3.8095238095238093),
'L': (2.380952380952381, 2.380952380952381),
'N': (17.142857142857142, 17.142857142857142)},
{'A': (2.5, 2.5),
'B': (1.25, 1.25),
'C': (3.75, 3.75),
'D': (1.875, 1.875),
'E': (2.5, 2.5),
'K': (5.0, 5.0),
'L': (3.125, 3.125),
'N': (22.5, 22.5)},
{'A': (2.7777777777777777, 2.2222222222222223),
'B': (1.3888888888888888, 1.1111111111111112),
'C': (4.166666666666666, 3.3333333333333335),
'D': (2.083333333333333, 1.6666666666666667),
'E': (2.7777777777777777, 2.2222222222222223),
'K': (5.555555555555555, 4.444444444444445),
'L': (3.4722222222222223, 2.7777777777777777),
'N': (25.0, 20.0)}]
for element in b:
sawst = df2[df2.operations.str.contains('cut', case=False)]
startt = sawst['start'].tolist()
duet = sawst['due'].tolist()
oper = sawst['operations'].tolist()
colNames = ['koszt[pln]', 'czas[h]']
ex = pd.DataFrame(element).T # transpose to look just like the sheet above
ex.columns = colNames
ex['czas[h]'] = ex['czas[h]'].round(2)
urzadzenie.append(maszyny)
# ex['czas[h]']=pd.to_datetime(ex['czas[h]'], unit='h').dt.strftime('%H:%M')
ex2 = ex.assign(operacje=oper, start=startt, due=duet)
ex2.index.name = 'orders'
print (ex2)
ex2.to_excel(r'C:\Users\DELL E6510\Desktop\XD\zasoby\nowe\ZASOBY_zam{}.xlsx', format(element))
我收到错误消息:InvalidWorksheetName:Excel工作表名称必须为<= 31个字符。
答案 0 :(得分:0)
可能的解决方案
替换: ex2.to_excel(r'C:\Users\DELL E6510\Desktop\XD\zasoby\nowe\ZASOBY_zam{}.xlsx', format(element))
使用
ex2.to_excel(r'C:\Users\DELL E6510\Desktop\XD\zasoby\nowe\ZASOBY_zam{}.xlsx', format(round(element["A"][0], 3)))