文章目录
1、 数据集说明
这是一份来自和鲸社区的倒闭企业数据集,总计 6,272 条记录,大小为 2.3 M,包含 21 个字段。
import matplotlib.pyplot as plt
import seaborn as sns
import datetime
import pandas as pd
data = pd.read_csv('com.csv')
data.head()
data['death_year']=pd.to_datetime(data['death_data']).dt.year
data['death_month']=pd.to_datetime(data['death_data']).dt.month
首先通过以上对数据的初步了解设立分析目标:
1、整体概况:分析各年份被淘汰的公司总数;按月份查看不同年份的淘汰情况;被淘汰公司的寿命;不同省市的整体情况;被淘汰的原因;
2、特定分析:抽取经济发达地区北、上、广作进一步的分析,主要淘汰的行业;公司类型;
2、各年份被淘汰的公司总数对比
plt.figure(1,figsize=(16,8))
sns.countplot(x='death_year',data=df,color='CadetBlue')
plt.title('各年份被淘汰的公司总数',fontsize=20)
plt.xlabel('')
plt.ylabel('')
plt.xticks(rotation=45)
plt.grid(False)
con=list(df.groupby('death_year').death_year.count().values)
for y,x in enumerate(con):
plt.text(y,x,'%s' %x,va='center',size=14)
公司倒闭得最多得年份竟然是2017年…
3、被淘汰公司的倒闭时间集中所在的月份
# 分析被淘汰的公司阵亡月份
data1=data[data['death_year'].isin(['2015','2016','2017','2018','2019'])]
plt.figure(1,figsize=(16,8))
sns.countplot(x='death_month',hue='death_year',data=data1,palette='Paired')
plt.title('2015-2019年各月份被淘汰的公司总数',fontsize=20)
4、被淘汰公司在倒闭当年的寿命
data['live_years']=data['live_days']/365
data['存活年限'] = pd.cut(x=data['live_years'],bins=[0,1,3,5,10,25])
sns.set_context("notebook", font_scale=1.3)
sns.catplot(x='death_year',y='live_days',hue='存活年限',kind='swarm',data=data,height=8,aspect=2,palette='Set2')
plt.title('各年份被淘汰公司的寿命',fontsize=20)
plt.xticks(rotation=45)
plt.show()
5、被淘汰公司的主要死亡原因
reason_index=data['death_reason'].value_counts()[1:11].index
reason=data.loc[data['death_reason'].isin(reason_index),'death_reason']
plt.figure(1,figsize=(16,8))
sns.countplot(x=reason.values,order=reason_index,color='CadetBlue')
plt.title('被淘汰公司的十大死亡原因',fontsize=20)
plt.ylabel('')
plt.xlabel('')
plt.xticks(rotation=45)
plt.grid(False)
con=list(data['death_reason'].value_counts()[1:11].values)
for y,x in enumerate(con):
plt.text(y,x,'%s' %x,va='center',size=14)
plt.show()
6、死亡公司的地区分布
from pyecharts import options as opts
from pyecharts.charts import Map
data['com_addr'] = data['com_addr'].apply(lambda x: x.strip())
s = data.groupby('com_addr').size()
c = (
Map()
.add("死亡企业数量", [*s.items()], "china")
.set_global_opts(
title_opts=opts.TitleOpts(title="地区分布"),
visualmap_opts=opts.VisualMapOpts(max_=200),
)
)
c.render_notebook()
7、行业排行TOP10
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.faker import Faker
s = data.groupby('cat').size().sort_values(ascending=False)[:10].to_dict()
c = (
Bar()
.add_xaxis(list(s.keys()))
.add_yaxis("死亡企业数量", list(s.values()))
.set_global_opts(title_opts=opts.TitleOpts(title="行业排行TOP10"))
)
c.render_notebook()
8、细分领域TOP20
s = data.groupby('se_cat').size().sort_values(ascending=False)[:20].sort_values(ascending=True).to_dict()
c = (
Bar()
.add_xaxis(list(s.keys()))
.add_yaxis("死亡企业数量", list(s.values()))
.reversal_axis()
.set_series_opts(label_opts=opts.LabelOpts(position="right"))
.set_global_opts(title_opts=opts.TitleOpts(title="细分领域TOP20"))
)
c.render_notebook()
9、年份分布
data['born_year'] = data['born_data'].apply(lambda x: x[:4])
data['death_year'] = data['death_data'].apply(lambda x: x[:4])
s1 = data.groupby('born_year').size()
s2 = data.groupby('death_year').size()
s1 = pd.DataFrame({'year': s1.index, 'born': s1.values})
s2 = pd.DataFrame({'year': s2.index, 'death': s2.values})
s = pd.merge(s1,s2, on='year', suffixes=['born', 'death'])
s = s[s['year'] > '2008']
c = (
Bar()
.add_xaxis( s['year'].to_list())
.add_yaxis("新生企业数量", s['born'].to_list())
.add_yaxis("死亡企业数量", s['death'].to_list())
.set_global_opts(title_opts=opts.TitleOpts(title="年份分布"))
)
c.render_notebook()
10、企业存活时长
def live_year(x):
if x < 365:
return '不到1年'
if x < 365 * 2:
return '1-2年'
if x < 365 * 3:
return '2-3年'
if x < 365 * 4:
return '3-4年'
if x < 365 * 5:
return '4-5年'
if x < 365 * 10:
return '5-10年'
return '10年以上'
s = data.groupby(data['live_days'].apply(lambda x: live_year(x))).size()
from pyecharts import options as opts
from pyecharts.charts import Pie
c = (
Pie()
.add("", [*s.items()])
.set_global_opts(title_opts=opts.TitleOpts(title="企业存活时长"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
)
c.render_notebook()
11、投资人词云
from pyecharts import options as opts
from pyecharts.charts import WordCloud
from pyecharts.globals import SymbolType
invest = {}
for row in data['invest_name'].values:
if not pd.isnull(row):
for name in row.split('&'):
invest[name] = invest.get(name, 0) + 1
invest = [*invest.items()]
invest.sort(key=lambda x: x[1], reverse=True)
c = (
WordCloud()
.add("", invest[:150], word_size_range=[20, 100], shape=SymbolType.DIAMOND)
.set_global_opts(title_opts=opts.TitleOpts(title="投资人词云"))
)
c.render_notebook()
12、倒闭原因词云
death_reason = {}
for row in data['death_reason'].values:
if not pd.isnull(row):
for name in row.split(' '):
death_reason[name] = death_reason.get(name, 0) + 1
c = (
WordCloud()
.add("", [*death_reason.items()], word_size_range=[20, 100], shape=SymbolType.DIAMOND)
.set_global_opts(title_opts=opts.TitleOpts(title="倒闭原因词云"))
)
c.render_notebook()
13、ceo描述词云
import jieba
ceo_per_des = {}
for row in data['ceo_per_des'].values:
if not pd.isnull(row):
result = jieba.lcut(row)
for name in result:
if len(name) == 1:
break
ceo_per_des[name] = ceo_per_des.get(name, 0) + 1
ceo_per_des = [*ceo_per_des.items()]
ceo_per_des.sort(key=lambda x: x[1], reverse=True)
c = (
WordCloud()
.add("", ceo_per_des[:100], word_size_range=[20, 100], shape=SymbolType.DIAMOND)
.set_global_opts(title_opts=opts.TitleOpts(title="ceo描述词云"))
)
c.render_notebook()