intersect-community-data icon indicating copy to clipboard operation
intersect-community-data copied to clipboard

Sort housing units by hu estimate

Open npr99 opened this issue 6 months ago • 1 comments

Exploring possible issue with merge between huestimate and census blocks

# Add counter by block id - use cumulative count method
        census_blocks_df_cols_expand['blockidcounter'] = \
            census_blocks_df_cols_expand.groupby(f'BLOCKID{yr}').cumcount()

        # Add counter by block id - use cumulative count method
        huesimate_df_cols_expand['blockidcounter'] = \
            huesimate_df_cols_expand.groupby(f'blockBLOCKID{yr}_str').cumcount()

        # Merge 2 files based on blockid and blockid counter - 
        # keep all observations from both files with full outer join
        address_point_inventory = pd.merge(left = huesimate_df_cols_expand, 
                                        right = census_blocks_df_cols_expand,
                                        left_on=[f'blockBLOCKID{yr}_str','blockidcounter'], 
                                        right_on=[f'BLOCKID{yr}_str','blockidcounter'], how='outer')

        # Error Checking
        # Save files to check for errors
        address_point_inventory.to_csv('address_point_inventory.csv', index=False)
        census_blocks_df_cols_expand.to_csv('census_blocks_df_cols_expand.csv', index=False)
        huesimate_df_cols_expand.to_csv('huesimate_df_cols_expand.csv', index=False)

Housing Unit by Building Estimates

Image

Housing Units by Block Level Estimates

Image

Address points Combined Housing Unit and Block

Image

In the example block (B410079501001004) - the building inventory suggests that there are 18 address points (6 do not have estimated housing units).

The census data reports there should be 12 housing units.

npr99 avatar Mar 27 '25 17:03 npr99