关于企查查处理数据的问题都可以私信我哦。 还可以整理分支机构、主要人员、投资信息、附属子公司等。
1、批量提取数据
由于需要区分工商登记数据还是最新公示数据,所以选择将这两部分数据分开存放,当然也可以放在一起。(本文认为最新公示的企业属于上市企业,但是也存在一些未上市却即将上市的企业,工商登记属于未上市企业)。
源数据截图示例:
代码:
import os
import re
import pandas as pd
folder_path = r"C:\股东信息解压"
latest_announcement_data = []
business_registration_data = []
for filename in os.listdir(folder_path):
if filename.endswith(".csv"):
file_path = os.path.join(folder_path, filename)
df = pd.read_csv(file_path, sep='\t', engine='python', skip_blank_lines=True)
df=df.astype(str)
df = df.applymap(lambda x: x.replace('=', '') if isinstance(x, str) else x)
df = df.applymap(lambda x: x.replace(',', '') if isinstance(x, str) else x)
df = df.applymap(lambda x: x.replace('""', '"') if isinstance(x, str) else x)
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
df = df[df['查企业 上企查查 , 联系电话:400-928-2212,'] != '" "']
current_state = None
current_company = None
for index, row in df.iterrows():
line = row[df.columns[0]]
company_match = re.match(r'"(.*)(公司|厂|大学|研究)(.*)', line)
if company_match:
current_company = company_match.group(1)+company_match.group(2)
if line.startswith('"股东信息-最新公示'):
current_state = "latest_announcement"
continue
elif line.startswit