I need to create an excel file which contains the output of different functions, such as dates, the number of duplicated variables... I managed to create an excel file that contains the output of the first function but when I tried to append it with the output of the 2nd funcion, it did not work. I don't know how to add the outputs of my different functions to the same excel file.
Example: function1:
import xlsxwriter
import openpyxl
import pandas as pd
def NGTP():
VIN_FFF = 0
N_Alert =0
for x in flat_list:
if "NGTPSM HTTP request" in str(x):
VIN_FFF+=1
N_Alert =5
workbook = xlsxwriter.Workbook('Results.xlsx')
worksheet = workbook.add_worksheet("sheet")
parametres = (
['VIN_FFF ', VIN_FFF],
['Nombre d alertes ', N_Alert],
)
# Start from the first cell. Rows and
# columns are zero indexed.
row = 0
col = 0
# Iterate over the data and write it out row by row.
for name, parametres in (parametres):
worksheet.write(row, col, name)
worksheet.write(row, col + 1, parametres)
row += 1
workbook.close()
function2:
import xlsxwriter
from openpyxl import load_workbook
from openpyxl import Workbook
import pandas as pd
filename = "Results.xlsx"
def Date2Roulage():
file_name='OutputDLT.xlsx'
df = pd.read_excel(file_name ,header=0, index= False)
d= df.iloc[0,2]
#d='2015-01-08 22:44:09'
date=pd.to_datetime(d).date()
date=list(date)
print('Date de roulage: ', date)
workbook = xlsxwriter.Workbook('Results.xlsx')
worksheet = workbook.add_worksheet("sheet")
parametres = (
['Date de roulage ', date],
)
# Start from the first cell. Rows and
# columns are zero indexed.
row = 2
col = 0
# Iterate over the data and write it out row by row.
for name, parametres in (parametres):
worksheet.write(row, col, name)
worksheet.write(row, col + 1, parametres)
row += 1
for row_ in parametres:
worksheet.append(row_)
workbook.save(filename)
workbook.close()
It does not produce an error, but I guess it's not working because i'm trying to create the same file twice simultaneously.
this is my main code:
from Date_de_roulage_Fct import *
from Navco_Fct import *
Date2Roulage()
Navco()
I've updated the second function, according to the suggested solution, but I got an error:
TypeError: 'datetime.date' object is not iterable
I trie this solution date=list(date)
and it did not work
The generated excel file must be vreated as shown is the image below: