Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I clearly see a positional argument defined, so why is it giving me this error?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading