проверьте это:
import pandas as pd
x = {
'app1': [0, 1, 2],
'app2': [0, 1, 2, 3, 4, 5],
'app3': [0, 1, 2, 3, 4, 5, 6, 7, 8]
}
temp = []
for app in x:
# chunk the list by the length of 3
chunks = [x[app][i:i+3] for i in range(0, len(x[app]), 3)]
# for all chunks add the value with the app name
for chunk in chunks:
temp.append(
[app, *chunk]
)
df = pd.DataFrame(temp, columns=('application', 'nodename', 'nodetier', 'nodeid'))
print(df)
дает:
application nodename nodetier nodeid
0 app1 0 1 2
1 app2 0 1 2
2 app2 3 4 5
3 app3 0 1 2
4 app3 3 4 5
5 app3 6 7 8
И, наконец, напишите в файл excel:
df.to_excel('excel_file')