I tried to use the pivot_table function on a dataframe. This was working at the beginning now I get all the time errors, and don't really get why.

cols = (['B', 'C', 'D', 'E'])
dataset[cols] = dataset[cols].apply(pd.to_numeric,errors='coerce', axis=1) 

score_table = dataset.pivot_table(index='A', values=['B', 'C'], aggfunc = np.mean)
plt.savefig(filename + 'figure_meanscore.pdf')

and thats my error:

numpy.core._exceptions.UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32')
  • 2
    $\begingroup$ if after this line dataset[cols] = dataset[cols].apply(pd.to_numeric,errors='coerce', axis=1) you run dataset.info() to check the value types, what does that return? Are the columns B and C numeric? can you share a pd.head of your dataframe? $\endgroup$ – Julio Jesus Jan 13 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.