<jupyter_start><jupyter_text>Gravity ModelThis script build a basic gravity model for analysis. Exemplary paper: Economic Outcome Predicted by DiversityQ: Need economic indicators (e.g. GDP) and jobs. Q: Unresolved - Traffic assignment problem.<jupyter_code>pwd
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpd
import geoplot
jobs_all = pd.read_csv("../data/SA2_Jobs_All_Jobs_and_Income.csv")
jobs_industries = pd.read_csv("../data/SA2_Jobs_In_Australia_Employee_Jobs_and_Income.csv")
jobs_all
jobs_industries
new_idx = []

for col in jobs_industries.columns:
    if col[0]==' ':
        new_idx.append(col[1:])
    else:
        new_idx.append(col)

jobs_industries.columns = new_idx
jobs_industries.columns
new_idx = []

for col in jobs_all.columns:
    if col[0]==' ':
        new_idx.append(col[1:])
    else:
        new_idx.append(col)

jobs_all.columns = new_idx
jobs_all.columns

jobs_all['sa2_code16'] = jobs_all['sa2_code16'].astype('str')

# notes:
# 'sa2_code16'

# read shapefile. 
sa2_shape = gpd.read_file("../data/sa2/SA2_2016_AUST.shp")
# Keep only the Adelaide area
adelaide_sa4_set=['401','402','403','404']
sa2_adelaide = sa2_shape.loc[sa2_shape.SA4_CODE16.isin(adelaide_sa4_set)]
print(sa2_adelaide.shape)
print(sa2_adelaide.head(10))

# merge
sa2 = pd.merge(sa2_adelaide, jobs_all, left_on='SA2_MAIN16', right_on='sa2_code16', how='inner')

sa2 # only the Adelaide area<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12065439672801637, 'fraction_numerical': 0.03749147920927062, 'mean_word_length': 5.327586206896552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '396017', 'license': 'MIT', 'n_tokens_mistral': 612, 'n_tokens_neox': 561, 'n_words': 109, 'path': 'notebooks/jason/9_gravity_model.ipynb', 'repo_name': 'cjsyzwsh/South_Australia_Transport_Econ', 'size': '1467'}