保存不同名称的文件

2024-09-28 19:20:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用不同的名称将这些打印的“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个字符


Tags: to名称elementexcelstartex表格operations
1条回答
网友
1楼 · 发布于 2024-09-28 19:20:01

可能的解决方案

替换: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)))

相关问题 更多 >