Python 无论我做什么,打印时都会出现语法错误。下面是代码,我可以';I don’我找不到问题所在

Python 无论我做什么,打印时都会出现语法错误。下面是代码,我可以';I don’我找不到问题所在,python,pandas,dataframe,printing,Python,Pandas,Dataframe,Printing,线路 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

线路

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())
缺少用于打印函数调用的括号。改成

    print c[['STNAME', 'CTYNAME']

您可以为三个最流行的县使用以下代码:

    print(c[['STNAME', 'CTYNAME'])

如果您使用的是Python3,则在打印的内容周围需要括号。它不再是语句另一个可能的副本的可能副本:print(question7())应该在Python 3中工作,然后。。。这应该是另一个问题?
def answer_six():
  largest = census_df.nlargest(3, ['CENSUS2010POP']) 
  return largest[['STNAME', 'CTYNAME', 'CENSUS2010POP']]