Python pandas axis error

–1 vote

I have the following python script:

sd=df.loc[:,[ "No. of Inmates benefitted byElementary Education",
"No. of Inmates benefitted by Adult Education",
"No. of Inmates benefitted by Higher Education", "No. of Inmates benefitted by Computer Course"]]
print(df[sd.sum(axis=1)]) -->this is giving row sum with axis =1 

Why is the following statement failing? with axis = 0, doesn't it mean it is column-wise sum?
print(df[sd.sum(axis=0)]) # Statement failing.

Jan 8, 2019 in Python by digger
• 26,660 points

1 answer to this question.

0 votes

When you are applying sum() you don't have to use df[] in df[sd.sum()] as you have already stored the required columns into sd dataframe. Hence to overcome this issue, please try by giving sd.sum(axis=0) instead of df[sd.sum(axis=0)]


import pandas as pd
sd=df.loc[: ,['No. of Inmates benefitted by Elementary Education','No. of Inmates benefitted by Adult Education','No. of Inmates benefitted by Higher Education']]
print(sd.sum(axis=1)) #row wise
print(sd.sum(axis=0)) #column wise
answered Jan 8, 2019 by Omkar
• 69,060 points

Related Questions In Python

0 votes
1 answer

Python Pandas error: AttributeError: 'DataFrame' object has no attribute 'rows'

There is no attribute called “rows”. The ...READ MORE

answered Mar 28, 2019 in Python by Shri
0 votes
1 answer

Python error "pandas.errors.ParserError: Error tokenizing data"

Pandas do not take .xlsx files. Rename ...READ MORE

answered Jun 13, 2019 in Python by Rhea
+2 votes
2 answers

Error while printing hello world in python.

You must be trying this command in ...READ MORE

answered Mar 31, 2018 in Python by GandalfDwhite
• 1,320 points
0 votes
2 answers

Indentation Error in Python

Use tabs instead of spaces. This is ...READ MORE

answered Feb 14, 2019 in Python by Shashank
• 1,370 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 929 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

Python argparse error "NameError: name 'file' is not defined"

The right datatype for destination in argpasrse module ...READ MORE

answered Nov 28, 2018 in Python by Omkar
• 69,060 points
0 votes
3 answers

Python error "NameError: name 'sr' is not defined"

NameError: name 'xx' is not defined Python knows ...READ MORE

answered Mar 19 in Python by rahul
• 320 points