0

For this dataframe:

t = pd.DataFrame({'a':np.random.randint(1,9,10), 'b':np.random.randint(1,9,10)})

I am trying to create a new columns by doing sum of each row:

t['sum'] = t.sum(axis=1)

but, when I try to retrieve the values by: t.sum.values I get the following error: AttributeError: 'function' object has no attribute 'values'

However, if I just sum the two columns manually t['sum2'] = t.a + t.b I can then get the column value by t.sum2.values without error. Can somebody explain to me what I have done wrong?

1 Answer 1

1

Cause sum is build in function for pandas

You should call the columns with

t['sum'].values

Rather than

t.sum.values#(wrong)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.