行政区划-基础数据处理

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24452475/article/details/84840445

写在前面

  • 在算法研发过程中,通常需要各类的基础数据。
    • 例如,下文中将要提到的行政区划编码与行政区划中文名。
  • 针对基础数据,如果处理不好,可能会对算法结果产生意想不到的影响。
  • 其中,行政区划翻译表中缺少地级市等行政编码,直接导致证件轨迹统计补全等问题,从而影响算法的准确性等

行政区划

1. 析取数据
import requests
import pandas as pd
from bs4 import BeautifulSoup

text = requests.get(u'http://www.mca.gov.cn/article/sj/tjbz/a/2018/201803131439.html').text
soup = BeautifulSoup(text,'lxml');

result = []
for item in soup.find_all('tr',attrs={"height":"19", "style":"mso-height-source:userset;height:14.25pt"}):
    ele = item.find_all('td',attrs={"class":"xl7013492"})
    if ele[0].getText() is not None and ele[0].getText()!='':
        result.append([ele[0].getText(), ele[1].getText()])
    
xzqh = pd.DataFrame(result)
xzqh.columns = ['xzqh_code','ch_name']

2. 具体效果

result


3. 下载地址

猜你喜欢

转载自blog.csdn.net/qq_24452475/article/details/84840445