I am trying to store a function parameter ‘n’ to an excel file however I receive an error:
AttributeError: 'int' object has no attribute 'to_excel'
I have a function that takes:
def test(alpha,a,x,y,n):
I need to store n (which is a single integer) in an excel file where I tried:
n.to_excel('n.xlsx')
However I receive the error as mentioned before. I tried to make an empty DataFrame and write n into the array which allows me to run the code however there is no value in the file. I have printed n in the function and it returns the integer so a bit confused on why I cannot save this value to an excel file?
>Solution :
You will need to install library openpyxl which can create and modify excel. The final code will look something like this:
from openpyxl import Workbook
def test(alpha,a,x,y,n):
wb = Workbook()
ws = wb.active
ws.append([n])
wb.save("sample.xlsx")
test(alpha=3, a = 4, x = 10, y = 15, n = 100)