address=df['address']
address.name='address'

def parse_rent(line):
    pattern=re.compile(r'[0-9,]+')
    result=pattern.search(line)
    if result:
        return result.group().replace(',','')
    else:
        return '0'

rent=df['rent']
rent=rent.apply(parse_rent)
rent.name='rent'

df.ix[8]['rent']

suburb=df['suburb']
suburb.name='suburb'

def parse_postcode(line):
    pattern=re.compile(r'\d{4}')
    result=pattern.search(line)
    if result:
        return result.group()
    else:
        return 'n/a'

postcode=suburb.apply(parse_postcode)

postcode.name='postcode'

postcode

"""
Explanation: 以下两句，就是从address出发搞到GPS地址，只须运行一次就可以
df['coordinate']=df['address'].apply(fetch_coordinates)
df.to_csv('./data/canberra_rent_new_csv')
End of explanation
"""


n=postcode.get_values().tolist()
p=[item for item in n if item=='n/a' ]

print(p)

new_df=pd.DataFrame()

new_df['postcode']=postcode
new_df['address']=address
new_df['rent']=rent
new_df

new_df.loc[:,'postcode']=new_df['postcode'].astype(int)
new_df.loc[:,'rent']=new_df['rent'].astype(int)

new_df

new_df.info()

new_df.describe()

import folium
import json

map=folium.Map(location=[-35.281990, 149.128747])

geo_json_data = json.load(open('./data/canberrageo.json'))

folium.GeoJson(geo_json_data).add_to(map)

map.save('canberra.html')

"""
Explanation: 简单的判断是否有'n/a'在Series中
End of explanation
"""


