I'm trying to create a database of orders. Very time program runs and user input their data - a different list is created containing this data. At the end of the program I add this data to a database. I use this currently to concatenate multiple lists and input to database in a format i need.
orderNumber = ['123456789']
countryOfOrigin = ['United Kingdom']
sizeList = ['2', '4']
quantityList = ['10', '12']
This is the output I get:
OrderNumber COO Size QTY
123456789 United Kingdom 2 10
123456789 United Kingdom 4 20
Note: number of rows is dictated by number of sizes... if other lists only have one item, the data is dublicated down to fill the rows.
This is the code used to create the DataFrame.
vals = [orderNumber, countryOfOrigin, sizeList, quantityList]
header = ["OrderNumber", "COO", "Size", "QTY"]
d = {a: b[0] if len(b) == 1 else b for a, b in zip(header, vals)}
order = pd.DataFrame(d)
And its simply saved into a document using this:
order.to_excel('C:/Users/userName/Desktop/Pandas-Example2.xlsx', index=False, encoding='utf-8')
This all works, but if the document is not available in the location path provided, it creates one. and if its already there. The data gets replaced with new data every time program runs.
I need it to NOT REPLACE whats already there, but rather find the last populated row, skip one (to create one row gap) and populate new data below.
I tried specifying the row in the:
bottom = excelFile.tail(1)
order.to_excel('C:/Users/userName/Desktop/Pandas-Example2.xlsx',
index=False, encoding='utf-8', startrow=bottom, startcol=1)
No Luck.