69 lines
2.8 KiB
Python
69 lines
2.8 KiB
Python
"""
|
|
小区属性导出
|
|
"""
|
|
from goojia_utils import MAIN_MONGO_CLIENT, dateutils, commutils
|
|
import pandas as pd
|
|
import datetime
|
|
import os
|
|
|
|
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
|
|
|
path = "/home/airflow/data/mt"
|
|
if not os.path.exists(path):
|
|
os.makedirs(path)
|
|
|
|
city_df = pd.read_excel('/opt/airflow/dags/repo/dags/mt/supply/data/美团19城市列表.xlsx')
|
|
cities = city_df['城市列表'].values.tolist()
|
|
|
|
seaweed_df = pd.DataFrame()
|
|
for city in cities:
|
|
temp_df = pd.DataFrame(list(seaweed_conn.find({'cat': 'district', 'status': 0, 'city': city}).batch_size(10000)))
|
|
seaweed_df = pd.concat([seaweed_df, temp_df])
|
|
|
|
seaweed_result_df = seaweed_df[
|
|
['_id', 'city', 'region', 'name', 'alias', 'address', 'addr_alias', 'lng', 'lat', 'block', 'loop_line_info',
|
|
'business_quarter',
|
|
'household_count', 'estate_charge', 'car_site_count', 'property_life', 'house_property', 'all_area', 'build_area',
|
|
'cubage_percent', 'virescence_percent', 'estate_type2', 'build_type', 'build_structure', 'finish_building_date',
|
|
'developer',
|
|
'main_type', 'main_type_area']]
|
|
|
|
|
|
def format_seaweed(x):
|
|
"""
|
|
格式化输出小区属性
|
|
:param x:
|
|
:return:
|
|
"""
|
|
names = [x.name]
|
|
try:
|
|
if x.alias is not None and str(x.alias) != 'nan':
|
|
names.extend(x.alias)
|
|
x.alias = ','.join(x.alias)
|
|
if x.addr_alias is not None and str(x.addr_alias) != 'nan':
|
|
x.addr_alias = ','.join(x.addr_alias)
|
|
x.virescence_percent = commutils.format_greening_rate(x.virescence_percent)
|
|
x.all_area = commutils.format_all_area(x.all_area)
|
|
x.build_area = commutils.format_build_area(x.build_area)
|
|
x.car_site_count = commutils.format_car_site_count(x.car_site_count)
|
|
x.household_count = commutils.format_household_count(x.household_count)
|
|
x.lng = commutils.format_lat_lng(x.lng)
|
|
x.lat = commutils.format_lat_lng(x.lat)
|
|
x.cubage_percent = commutils.format_plot_ratio(x.cubage_percent)
|
|
if type(x.alias) == str and '@' in x.alias:
|
|
x.alias = None
|
|
|
|
return x
|
|
except Exception as e:
|
|
print(e)
|
|
print(x)
|
|
pass
|
|
|
|
|
|
seaweed_new_result_df = seaweed_result_df.apply(lambda x: format_seaweed(x), axis=1)
|
|
seaweed_new_result_df = seaweed_new_result_df.rename(columns={'_id': 'id', 'household_count': 'households', 'estate_charge': 'property_fee',
|
|
'cubage_percent' : 'plot_ratio', 'virescence_percent': 'landscaping_ratio', 'estate_type2': 'property_type',
|
|
'main_type': 'house_type', 'main_type_area': 'house_area'})
|
|
seaweed_new_result_df.to_csv(path + '/FJW_COMM_' + dateutils.format_date(datetime.datetime.now(), '%Y%m') + '.csv',
|
|
sep='@', encoding='utf-8', index=False)
|