数据如下
![](https://i-blog.csdnimg.cn/blog_migrate/a524149dd7ff63e336e30afa8b92bcc5.png)
代码如下
import pymysql
import pandas as pd
import re
db = pymysql.connect(
port=3306,
user='root',
password='xxx',
db='xxx',
charset='utf8'
)
sql = 'select * from java'
data = pd.read_sql(sql, db)
# # 福利
data = data[(data['info_desc'].values == '') == False]
print(data['info_desc'])
# # 地区
data['area_city'] = data['area'].str.split("·").str[0]
# data['area_cou'] = data['area'].str.split("·").str[1]
# data['area_detail'] = data['area'].str.split("·").str[2]
# # 学历
data['edu_list_new'] = data["edu_list"].str.split('\\n').str[1]
# 薪资
data = data.drop(data[data['salary'].str.contains(pat='元/天', regex=False)].index)
data = data.drop(data[data['salary'].str.contains(pat='元/月', regex=False)].index)
data = data.drop(data[data['salary'].str.contains(pat='元/周', regex=False)].index)
data["new_salray"] = ((data['salary'].str.split('K').str[0].str.split('-').str[0].astype(int) +
data['salary'].str.split('K').str[0].str.split('-').str[1].astype(int)) / 2 * (
data['salary'].str.split("·").str[1].str.replace('薪', '').fillna(12).values.astype(int)))
# 规模
ls = []
for i in data["company_tag_list"]:
# print(i)
if re.search('\d+.*', i):
result = re.search('\d+.*', i).group()
# print(result)
else:
print('none')
ls.append(result)
data["company_size"] = ls
data["company_size"] = data['company_size'].str.replace('[\u4e00-\u9fa5]','').str.split('-')
data_new = data[['title', 'area_city', 'edu_list_new', 'new_salray', 'company_name', 'company_size']]
结果如下
![](https://i-blog.csdnimg.cn/blog_migrate/8be6317e446e54462464b0de2825ec07.png)