<jupyter_start><jupyter_text>import<jupyter_code>import pandas as pd
import numpy as np
import re<jupyter_output><empty_output><jupyter_text>function<jupyter_code>kanji   = ["〇","一","二","三","四","五","六","七","八","九"]
zenkaku = ["０","１","２","３","４","５","６","７","８","９"]
hankaku = ["0","1","2","3","4","5","6","7","8","9"]

zen2kanji = {}
for z, k in zip(zenkaku, kanji) : zen2kanji[z] = k
    
zen2han = {}
for z, k in zip(zenkaku, hankaku) : zen2han[z] = k
def changestr(instr, dic):
    
    out = []
    for v in instr:
        out.append(dic[v])
        
    return ''.join(out)<jupyter_output><empty_output><jupyter_text>load data file<jupyter_code>dfhigai = pd.read_csv('higaihasseibijun.csv')
chofuaddress = pd.read_csv('13208_2018.csv', encoding='SHIFT-JIS')<jupyter_output><empty_output><jupyter_text>Search latitude and longitude from address<jupyter_code>ad = dfhigai['住所'].values

ooaza = []
tiban = []

for v in ad:
    name = re.split('[０-９]', v)[0]
    n1 = re.split(name[-1], v)
    nn = n1[-1].split('－')
    ooaza.append( name + changestr(nn[0],zen2kanji) + '丁目' )
    tiban.append( changestr(nn[-1], zen2han) )
lon, lat = [], []

for o, t in zip(ooaza, tiban):
    pick = chofuaddress[ (chofuaddress['大字・丁目名'] == o) & (chofuaddress['街区符号・地番'] == int(t)) ]
    
    c = pick['経度'].values
    
    if len(c) == 0:
        lon.append(0)
        lat.append(0)
    elif len(c) > 1:
        pick2 = chofuaddress[ (chofuaddress['大字・丁目名'] == o) 
                            & (chofuaddress['街区符号・地番'] == int(t)) 
                            & (chofuaddress['代表フラグ'] == 1 ) ]
        
        if len(pick2['経度'].values) != 1 : print('error')
        lon.append(pick2['経度'].values[0])
        lat.append(pick2['緯度'].values[0])
    else:
        lon.append(pick['経度'].values[0])
        lat.append(pick['緯度'].values[0])<jupyter_output><empty_output><jupyter_text>Add pandas dataframe and export csv file<jupyter_code>dfhigai.columns = ['address','damage','date','cause']
dfhigai['longitude'] = np.array(lon)
dfhigai['latitude'] = np.array(lat)
dfhigai
dfhigai.to_csv('data.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2096545196403218, 'fraction_numerical': 0.02744912446758164, 'mean_word_length': 3.7828054298642533, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '263643', 'license': 'MIT', 'n_tokens_mistral': 938, 'n_tokens_neox': 908, 'n_words': 131, 'path': 'data-flooddamage/Preprocessing.ipynb', 'repo_name': 'computational-sediment-hyd/chofu-flooddamage', 'size': '2113'}