Hi Everyone,
I am trying to sum a column in a dataframe where the substring of another column is equal to a certain value.
My code is:
File "<ipython-input-20-4a7a35ac591d>", line 1
sums['Meat'] = data['Imports ($NZD cif)'].sum(axis=1).where(data['Harmonised System Code'].str.slice(0,3) = '2013')
^
SyntaxError: keyword can't be an expression
I don't think it likes the where statement. Anyone know how I go about this?
Thanks for any help :)
I am trying to sum a column in a dataframe where the substring of another column is equal to a certain value.
My code is:
sums['Meat'] = data['Imports ($NZD cif)'].sum(axis=1).where(data['Harmonised System Code'].str.slice(0,3) = '2013')My error note is :
File "<ipython-input-20-4a7a35ac591d>", line 1
sums['Meat'] = data['Imports ($NZD cif)'].sum(axis=1).where(data['Harmonised System Code'].str.slice(0,3) = '2013')
^
SyntaxError: keyword can't be an expression
I don't think it likes the where statement. Anyone know how I go about this?
Thanks for any help :)
Larz60+ write Jan-11-2021, 09:41 AM:
Please, Always post entire unmodified error traceback in error tags.
there is important information within that will help with debugging.
Please, Always post entire unmodified error traceback in error tags.
there is important information within that will help with debugging.