import csv
import numpy as np
import pandas as pd
# QUESTION 5; Only looking at the three most populous counties for each state, what are the three
# most populous states (in order of highest population to lowest population)?
# Use `CENSUS2010POP
census_df = pd.read_csv('census.csv')
census_df.head()
def question7():
return "hllo"
def question8():
c = census_df
c = c[(c['REGION'] == 1) | (c['REGION'] == 2)] # region 1 or 2
c = c.where(c['CTYNAME'].str.startswith('Washington')).dropna() # Washington name
c = c[c['POPESTIMATE2015'] > c['POPESTIMATE2014']] #POP 15 > POP 14
c = c.sort_index(ascending=True)
print c[['STNAME', 'CTYNAME']
print (question7())
Asked
Active
Viewed 213 times
-4

user3483203
- 50,081
- 9
- 65
- 94

Rami.K
- 189
- 2
- 11
-
3If you're using Python 3, you need parenthesis around whatever you are printing. It is no longer a statement – user3483203 Aug 06 '18 at 01:40
-
Possible duplicate of [What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?](https://stackoverflow.com/questions/25445439/what-does-syntaxerror-missing-parentheses-in-call-to-print-mean-in-python) – U13-Forward Aug 06 '18 at 02:43
-
Anther Possible duplicate: [Syntax error on print with Python 3](https://stackoverflow.com/questions/826948/syntax-error-on-print-with-python-3) – U13-Forward Aug 06 '18 at 02:43
-
1print(question7()) should work in Python 3 then... this should be a different issue.. ? – Rami.K Aug 06 '18 at 03:07
2 Answers
0
The line
print c[['STNAME', 'CTYNAME']
is missing parentheses for the print function call. Change it to,
print(c[['STNAME', 'CTYNAME'])

gilch
- 10,813
- 1
- 23
- 28
0
You can use below code for three most pop counties :
def answer_six():
largest = census_df.nlargest(3, ['CENSUS2010POP'])
return largest[['STNAME', 'CTYNAME', 'CENSUS2010POP']]

Ahmad Hassani
- 1
- 1