繁体   English   中英

无论我做什么,我都会在打印时遇到语法错误。 这是下面的代码,我找不到问题所在

[英]Whatever I do, I get syntax error on print. Here is the code below, i can't find what is wrong

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'])

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

def answer_six():
  largest = census_df.nlargest(3, ['CENSUS2010POP']) 
  return largest[['STNAME', 'CTYNAME', 'CENSUS2010POP']]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM