1. <tfoot id='jQMdu'></tfoot>
        <bdo id='jQMdu'></bdo><ul id='jQMdu'></ul>

      <small id='jQMdu'></small><noframes id='jQMdu'>

      <i id='jQMdu'><tr id='jQMdu'><dt id='jQMdu'><q id='jQMdu'><span id='jQMdu'><b id='jQMdu'><form id='jQMdu'><ins id='jQMdu'></ins><ul id='jQMdu'></ul><sub id='jQMdu'></sub></form><legend id='jQMdu'></legend><bdo id='jQMdu'><pre id='jQMdu'><center id='jQMdu'></center></pre></bdo></b><th id='jQMdu'></th></span></q></dt></tr></i><div id='jQMdu'><tfoot id='jQMdu'></tfoot><dl id='jQMdu'><fieldset id='jQMdu'></fieldset></dl></div>

      <legend id='jQMdu'><style id='jQMdu'><dir id='jQMdu'><q id='jQMdu'></q></dir></style></legend>

      使用 python {census} 计算每个州的县数

      Count number of counties per state using python {census}(使用 python {census} 计算每个州的县数)

          <bdo id='Oy74L'></bdo><ul id='Oy74L'></ul>
        • <legend id='Oy74L'><style id='Oy74L'><dir id='Oy74L'><q id='Oy74L'></q></dir></style></legend>

          <small id='Oy74L'></small><noframes id='Oy74L'>

          <i id='Oy74L'><tr id='Oy74L'><dt id='Oy74L'><q id='Oy74L'><span id='Oy74L'><b id='Oy74L'><form id='Oy74L'><ins id='Oy74L'></ins><ul id='Oy74L'></ul><sub id='Oy74L'></sub></form><legend id='Oy74L'></legend><bdo id='Oy74L'><pre id='Oy74L'><center id='Oy74L'></center></pre></bdo></b><th id='Oy74L'></th></span></q></dt></tr></i><div id='Oy74L'><tfoot id='Oy74L'></tfoot><dl id='Oy74L'><fieldset id='Oy74L'></fieldset></dl></div>
                <tbody id='Oy74L'></tbody>
              • <tfoot id='Oy74L'></tfoot>

                本文介绍了使用 python {census} 计算每个州的县数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我很难用著名的 cenus.csv 数据.

                I am troubling with counting the number of counties using famous cenus.csv data.

                任务:统计每个州的县数.

                Task: Count number of counties in each state.

                面对比较(我认为)/请阅读以下内容?

                Facing comparing (I think) / Please read below?

                我试过了:

                df = pd.read_csv('census.csv')
                dfd = df[:]['STNAME'].unique()  //Gives out names of state
                
                serr = pd.Series(dfd)  // converting to series (from array)
                

                在此之后,我尝试了两种方法:

                After this, i've tried using two approaches:

                1:

                    df[df['STNAME'] == serr] **//ERROR: series length must match**
                

                2:

                i = 0
                for name in serr:                        //This generate error 'Alabama'
                    df['STNAME'] == name
                    for i in serr:
                        serr[i] == serr[name]
                        print(serr[name].count)
                        i+=1
                

                请指导我;这东西已经用了三天了.

                Please guide me; it has been three days with this stuff.

                推荐答案

                使用 groupby 并使用 nunique 聚合 COUNTY:

                Use groupby and aggregate COUNTY using nunique:

                In [1]: import pandas as pd
                
                In [2]: df = pd.read_csv('census.csv')
                
                In [3]: unique_counties = df.groupby('STNAME')['COUNTY'].nunique()
                

                现在结果

                In [4]: unique_counties
                Out[4]: 
                STNAME
                Alabama                  68
                Alaska                   30
                Arizona                  16
                Arkansas                 76
                California               59
                Colorado                 65
                Connecticut               9
                Delaware                  4
                District of Columbia      2
                Florida                  68
                Georgia                 160
                Hawaii                    6
                Idaho                    45
                Illinois                103
                Indiana                  93
                Iowa                    100
                Kansas                  106
                Kentucky                121
                Louisiana                65
                Maine                    17
                Maryland                 25
                Massachusetts            15
                Michigan                 84
                Minnesota                88
                Mississippi              83
                Missouri                116
                Montana                  57
                Nebraska                 94
                Nevada                   18
                New Hampshire            11
                New Jersey               22
                New Mexico               34
                New York                 63
                North Carolina          101
                North Dakota             54
                Ohio                     89
                Oklahoma                 78
                Oregon                   37
                Pennsylvania             68
                Rhode Island              6
                South Carolina           47
                South Dakota             67
                Tennessee                96
                Texas                   255
                Utah                     30
                Vermont                  15
                Virginia                134
                Washington               40
                West Virginia            56
                Wisconsin                73
                Wyoming                  24
                Name: COUNTY, dtype: int64
                

                这篇关于使用 python {census} 计算每个州的县数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                <i id='u8uWB'><tr id='u8uWB'><dt id='u8uWB'><q id='u8uWB'><span id='u8uWB'><b id='u8uWB'><form id='u8uWB'><ins id='u8uWB'></ins><ul id='u8uWB'></ul><sub id='u8uWB'></sub></form><legend id='u8uWB'></legend><bdo id='u8uWB'><pre id='u8uWB'><center id='u8uWB'></center></pre></bdo></b><th id='u8uWB'></th></span></q></dt></tr></i><div id='u8uWB'><tfoot id='u8uWB'></tfoot><dl id='u8uWB'><fieldset id='u8uWB'></fieldset></dl></div>

                1. <legend id='u8uWB'><style id='u8uWB'><dir id='u8uWB'><q id='u8uWB'></q></dir></style></legend>
                    <tbody id='u8uWB'></tbody>
                    • <bdo id='u8uWB'></bdo><ul id='u8uWB'></ul>
                      <tfoot id='u8uWB'></tfoot>

                        <small id='u8uWB'></small><noframes id='u8uWB'>