<jupyter_start><jupyter_text>Merge Berkeley tree data with Berkeley zip code shapes<jupyter_code>import pandas as pd
import geopandas as gpd
import rtree
import requests<jupyter_output>/Users/gracelynnewest/.pyenv/versions/3.8.5/envs/berkeley_tree_data-3.8.5/lib/python3.8/site-packages/pandas/compat/__init__.py:124: UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.
  warnings.warn(msg)<jupyter_text>Zip code shapefileDownloaded the zip code shapefile from [UC Berkeley](https://geodata.lib.berkeley.edu/catalog/ark28722-s7h597) as `ark28722-s7h597-geojson.json`.<jupyter_code>zip_code_shapefile = gpd.read_file('ark28722-s7h597-geojson.json')
zip_code_shapefile
zip_code_shapefile[['ZIP', 'POP2007', 'POP07_SQMI', 'SQMI']].to_csv('../berkeley_zip_codes.csv', index=False)<jupyter_output><empty_output><jupyter_text>Download zip codes and tree data<jupyter_code># Download tree data
r = requests.get('https://data.cityofberkeley.info/api/geospatial/9t35-jmin?method=export&format=GeoJSON', allow_redirects=False)

# write the content of the request into a file called `berkeley_311.csv`
open('city_trees.geojson', 'wb').write(r.content)
berkeley_trees = gpd.read_file('city_trees.geojson')
berkeley_trees
trees_with_zip = gpd.sjoin(berkeley_trees, zip_code_shapefile, how='left', predicate='within')
trees_with_zip
# removing unnecessary columns
del trees_with_zip['id']
del trees_with_zip['PO_NAME']
del trees_with_zip['STATE']
del trees_with_zip['SUMBLKPOP']
del trees_with_zip['Shape_Leng']
del trees_with_zip['Shape_Area']
del trees_with_zip['POP2007']
del trees_with_zip['POP07_SQMI']
del trees_with_zip['SQMI']
trees_with_zip
del trees_with_zip['index_right']
del trees_with_zip['OBJECTID']
trees_with_zip.to_csv('../berkeley_trees_with_zip.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11755403268318397, 'fraction_numerical': 0.02952029520295203, 'mean_word_length': 8.537688442211055, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '453196', 'license': 'MIT', 'n_tokens_mistral': 750, 'n_tokens_neox': 683, 'n_words': 122, 'path': 'zip_code_shapefile/zip_codes.ipynb', 'repo_name': 'gwest650/berkeley_tree_data', 'size': '1897'}