Issue
I'm trying to condense my file format. I've changed the headers to match my function. It's worked previously, but with this new file I'm getting a positional argument error.
input_fname = 'basic.xlsx' # input filename
output_fname = 'basic-condensed.xlsx' # output filename
basic_all = pd.read_excel(input_fname)
catalog_id_column = 'Product Number'
price_columns = 'List Price'
size_column = 'Size'
basic_all_condensed = condense_excel_multiprice(basic_all, price_columns, size_column)
writer = pd.ExcelWriter(output_fname,
engine='xlsxwriter',
options={'strings_to_urls': False})
gbio_abs_condensed.to_excel(writer, index=False, encoding='utf-8')
writer.close()
TypeError Traceback (most recent call last)
<ipython-input-146-614ba8c55380> in <module>
22
23
---> 24 basicbio_all_condensed = condense_excel_multiprice(basicbio_all, price_columns, size_column)
25
26 writer = pd.ExcelWriter(output_fname,
TypeError: condense_excel_multiprice() missing 1 required positional argument: 'size_column
Solution
Just because you have a variable called size_column
doesn't mean it was passed in the same/correct position that your function's signature expected.
Take this example:
def foo(x, y, ax=None):
return x + y
y = 1
foo(y)
This generates the error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-cf0d9fb1194f> in <module>
3
4 y = 1
----> 5 foo(y)
TypeError: foo() missing 1 required positional argument: 'y'
That's because I'm passing y
as the first agrument, which my function refers to as x
. Even though I passed y
, I'm still missing one argument
Answered By - Paul H
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.