简体   繁体   English

在python中打印具有特定值的列

[英]Print column with a specific value in python

I am using Colab.I am trying to print data form only NY,NC, SC State我正在使用 Colab。我正在尝试仅打印 NY、NC、SC 州的数据表

confirmed_cases_USA, deaths_USA = get_confirmed_deaths_tuple_df (USA_covid_data)

# selecting rows based on condition PA, IL,OH,GA ,NC 

options = ['NC',"PA"] 
#options = ['NC',"PA","IL","OH","GA"] 
confirmed_cases_Selected = confirmed_cases_USA[confirmed_cases_USA ['State'].isin(options)] 
deaths_Selected= deaths_USA [deaths_USA ['State'].isin(options)]

print(confirmed_cases_Selected.head())
print(deaths_Selected.head())

output is :输出是:

countyFIPS            County Name         State  ...  9/19/20  9/20/20  
1921           0  Statewide Unallocated    NC  ...     1166     1166     1166
1922       37001        Alamance County    NC  ...     3695     3728     3749
1923       37003       Alexander County    NC  ...      483      485      488
1924       37005       Alleghany County    NC  ...      219      220      220
1925       37007           Anson County    NC  ...      549      552      553




    countyFIPS            County Name State  ...  9/19/20  9/20/20  
1921           0  Statewide Unallocated    NC  ...        0        0        
1922       37001        Alamance County    NC  ...       48       54       54
1923       37003       Alexander County    NC  ...        5        5        5
1924       37005       Alleghany County    NC  ...        0        0        0
1925       37007           Anson County    NC  ...        4        4        4

I am trying to Group the data by state first and then get the total to confirm case of the state我试图首先按州对数据进行分组,然后得到总数以确认该州的情况

I'm not sure what get_confirmed_deaths_tuple_df does but it doesn't look like a DataFrame.我不确定get_confirmed_deaths_tuple_df做了什么,但它看起来不像数据帧。

USA_covid_data['State'].isin(options) should return a boolean mask containing True and False . USA_covid_data['State'].isin(options)应该返回一个包含TrueFalse的布尔掩码。 Return the values that satisfy the True condition with USA_covid_data[USA_covid_data['State'].isin(options)]使用USA_covid_data[USA_covid_data['State'].isin(options)]返回满足True条件的值

It should look something like this.它应该看起来像这样。

confirmed_cases_USA, deaths_USA = get_confirmed_deaths_tuple_df(USA_covid_data[USA_covid_data['State'].isin(options)])

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

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