0

I am new to Python, kindly help me to understand and go forward in python learning. Find below the sample data:

Country Age Sal OnWork
USA 52 12345 No
UK 23 1142 Yes
MAL 25 4456 No

I would like to find the mean value in SAL column if OnWork is NO

3
  • County Age Salary OnWork USA 52 11456 No UK 25 1235 Yes Singapore 45 4456 No Not sure how to update Table format here..... Commented Sep 21, 2019 at 0:48
  • 1
    please explain your question . Commented Sep 21, 2019 at 0:49
  • Welcome to StackOverflow. Please follow the posting guidelines in the help documentation, as suggested when you created this account. On topic, how to ask, and ... the perfect question apply here. StackOverflow is not a design, coding, research, or tutorial resource. However, if you follow whatever resources you find on line, make an honest solution attempt, and run into a problem, you'd have a good example to post. Commented Sep 21, 2019 at 0:50

1 Answer 1

1

Let's Say that your data looks like the following,

{'Country': 'USA', 'Age': '52', 'Sal': '12345', 'OnWork': 'No'}
{'Country': 'UK', 'Age': '23', 'Sal': '1142', 'OnWork': 'Yes'}
{'Country': 'MAL', 'Age': '25', 'Sal': '4456', 'OnWork': 'No'}

The below code will be of help in your case:

df = your_dataframe
df[df["OnWork"]=="No"]["Sal"].mean()
Sign up to request clarification or add additional context in comments.

4 Comments

Whether I can use IF of Where class to find YES and NO values mean.
You can use df.filter(items = ["OnWork","Sal"],axis=1).groupby(by = ["OnWork"]).mean()
I am getting IndentationError: unexpected indent error. The real spreadsheet has more than 10k lines in 7coloums
please check your code indentation, if problem still persists please post the complete traceback by editing the question.

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.