Question

import pandas as pd df=pd.read_csv(r"D:\Datasets\Salaries.csv") df.head() index rank discipline phd service sex salary 0 1 Prof...

import pandas as pd
df=pd.read_csv(r"D:\Datasets\Salaries.csv")
df.head()
 
  index            rank discipline  phd  service     sex    salary
0      1             Prof          B          19       18       Male  139750
1      2             Prof          B          20       16       Male  173200
2      3      AsstProf          B           4         3    Female    79750
3      4             Prof          B          45       39       Male  115000
4      5             Prof          B          40       41       Male  141500

==============================================================================================

From the above Data Frame,

(1) Write a program that selects all female faculty whose service years is greater than 15, salary is greater than 100,000 and discipline is B.

(2) Find the average salary of the selected faculty in (1)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution

1)  df1=df[(df["sex"]=="Female")  & (df["salary"]>100000) & (df["discipline"]=="B") & (df["service"]>15)]

2) salary=df1["salary"].mean()

-------

for 1) I have clubbed all the conditions into a single statement, we can write them separately as well. It is very self-explanatory i believe.

the average of a column can be calculated by using the mean() method.

-------

Add a comment
Know the answer?
Add Answer to:
import pandas as pd df=pd.read_csv(r"D:\Datasets\Salaries.csv") df.head() index rank discipline phd service sex salary 0 1 Prof...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • do it in python 1. Import the proper libraries: Pandas and NumPy and create aliases pd,...

    do it in python 1. Import the proper libraries: Pandas and NumPy and create aliases pd, np respectively. 2. Load sample data (car_loan.csv) into data frame: df 3. Export Pandas DataFrames to csv. Save file name as out.csv. hint: help(df.to_csv) 4. Run the command: df.info (). What do you see, how many columns? also what about number of entries for each column 5. It is often the case where you change your column names or remove unnecessary columns. a. Change...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT