本资料为最新整理的全国行政区划数据表,数据截至到2018年9月1日,共包含省市区4291个(34个省份 396个城市 3857个区县),内容包含名称、全称、全拼、简拼、省市区聚合、邮编、经度、纬度等!是大数据分析必备资料。
链接: https://pan.baidu.com/s/1IOJSko-YpSNp6ojqTTbeXQ
密码: jd6f
内容截图如下:
Django Model 设计
class AdminDivision(models.Model):
name = models.CharField('名称', max_length=100)
name_short = models.CharField('简称', max_length=100)
quanpin = models.CharField('全拼', max_length=200, null=True)
jianpin = models.CharField('简拼', max_length=200, null=True)
merger_name = models.CharField('合并名称',max_length=100, null = True)
full_name = models.CharField('全名称',max_length=100, null = True)
post_name = models.CharField('邮寄名称',max_length=100, null = True)
merger_short_name = models.CharField('合并简称',max_length=100)
level_type = models.IntegerField('行政级别')
city_code = models.CharField('城市代码',max_length=50, null = True)
zip_code = models.CharField('邮政代码',max_length=50, null = True)
jingdu = models.DecimalField('经度',max_digits=12, decimal_places=8, null = True)
weidu = models.DecimalField('纬度',max_digits=12, decimal_places=8, null = True)
remark1 = models.CharField('备注1', max_length=200, null=True)
remark2 = models.CharField('备注2', max_length=200, null=True)
old_id = models.IntegerField('old_id')
old_parent_id = models.IntegerField('old_parent_id')
parent = models.ForeignKey('self', verbose_name='上级', null = True, on_delete = models.CASCADE)
class Meta:
verbose_name = '行政区划'
def __str__(self):
return self.name
django 导入方法
def import_admin_div_info():
'''导入原始数据'''
data_dir = './data/'
file_name = '2018_admin_div.xls'
path = os.path.abspath(os.path.join(data_dir, file_name))
counter = 0
try:
import pdb;pdb.set_trace()
admin_div_info = read_excel(path)
admin_div_info_list = []
for div_info in admin_div_info:
old_id = div_info['ID']
old_parent_id = div_info['ParentId']
name = div_info['Name']
name_short = div_info['ShortName']
quanpin = getQuanPin(name_short)
jianpin = getJianPin(name_short)
merger_short_name = div_info['MergerShortName']
level_type = div_info['LevelType']
city_code = div_info['CityCode']
zip_code = div_info['ZipCode']
jingdu = decimal.Decimal(div_info['lng'])
weidu = decimal.Decimal(div_info['Lat'])
remark1 = div_info['Remark1']
remark2 = div_info['Remark2']
admin_div_info_list.append(
AdminDivision(
old_id = old_id,
old_parent_id =old_parent_id,
name =name,
name_short = name_short,
quanpin = quanpin,
jianpin = jianpin,
merger_short_name = merger_short_name,
level_type = level_type,
city_code = city_code,
zip_code = zip_code,
jingdu = jingdu,
weidu = weidu,
remark1 =remark1,
remark2 =remark2,
)
)
counter+=1
AdminDivision.objects.bulk_create(admin_div_info_list)
print('total import {} divs'.format(counter))
except Exception as e:
print(str(e))