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)
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.
-------
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...
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...