Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions ex5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
###Exercise 5-1###
import pandas as pd
wages=pd.read_table("wages.csv",",")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can just use read_csv:
wages=pandas.read_csv("wages.csv")

gen_years=wages.iloc[0:len(wages),0:2]
gen_years=gen_years.sort_values(by=['gender','yearsExperience'], ascending=[1,1])

@lyy005 lyy005 Oct 5, 2017

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question was asking to print out only the unique combinations. You can use drop_duplicates to only keep the unique combinations:
unique_genderYears=genderYears.drop_duplicates()

-0.25

gen_years.to_csv('ex5_1.txt', header=True, index=False, sep=" ")

###Exercise 5-2###
import pandas as pd
wages=pd.read_table("wages.csv",",")
wage_low=wages.iloc[0:len(wages),[0,1,3]]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can use:
wage_low=wages.iloc[:,[0,1,3]]

wage_low=wage_low.sort_values(by=['wage'], ascending=[1])
print ("The lowest wage in both genders is:")
print (wage_low[:1])

wage_high=wages.iloc[0:len(wages),[0,1,3]]
wage_high=wage_high.sort_values(by=['wage'], ascending=[0])
print ("The highest wage in both genders is:")
print (wage_high[:1])

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job

wages_10=wage.high.iloc[0:10,0:2]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wage.high should be wage_high

Ftot=wages_10.gender.eq('female').sum()
print ("Number of Females in the Top 10 Wages:")
print (Ftot)

###Exercise 5-3###
import pandas as pd
wages=pd.read_table("wages.csv",",")
no_college=min(wages.wage[wages.yearsSchool==12])
yes_college=min(wages.wage[wages.yearsSchool==16])

print("The minimum wage for non college grads is", no_college)
print("The minimum wage for college grads is", yes_college)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job

Loading