Cell In[13], line 3
pie=(
^
SyntaxError: '(' was never closed
修改Date列
#df['Date']#转换成字符串类型
df['Date']= df['Date'].astype(str)#定义函数,实现date列格式统一:年-月-日deftrans_date(tag):if tag.startswith("20"):#查看是否以20开头,即查看是否存在年
tag = tag.replace(".","-")else:
tag ="2025-"+ tag.replace(".","-")#否则加上年份2025return tag
df['Date']= df['Date'].map(lambda x: trans_date(x))#调用函数转换格式#转换成日期类型
df['Date']= pd.to_datetime(df['Date'])#df.info()
数据可实化
from pyecharts.globalsimport ThemeType
查看患者性别分布情况
# 准备数据:按照性别统计个数
data = df['Sex'].value_counts()# data
x = data.index.tolist()
y = data.tolist()# 绘制饼图
pie=(
Pie(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))#设置主题.add("",[list(z)for z inzip(x,y)],#数据需要打包成[(key,value),(key,value),...]
label_opts=opts.LabelOpts(formatter="{b}:{d}%")#以百分比形式显示标签).set_global_opts(title_opts=opts.TitleOpts(title="患者性别分布情况")))
pie.render_notebook()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[24], line 12
8 y=data.tolist()
10 #画柱状图
11 line=(
---> 12 Line(init_opts=opts.InitOpts(theme=ThemeType.DARK)) #主题配置
13 .add_xaxis(x)
14 .add_yaxis("人数",y)
15 .set_global_opts(title_opts=opts.TitleOpts(title="患者就诊分布情况"),
16 xaxis_opts=opts.AxisOpts(type_="category"),
17 yaxis_opts=opts.AxisOpts(type_="value"),)
18 .reversal_axis()
19 )
20 line.render_notebook()
NameError: name 'Line' is not defined
患者标签
pip install jieba
import jieba
from collections import Counter
defchinese_word_cut(text):
seg_list = jieba.cut(text, cut_all=False)return[word for word in seg_list iflen(word)>1]
all_word =[]for text in df['Title']:
all_word.extend(chinese_word_cut(text))
word_count = Counter(all_word)
top_words = word_count.most_common(100)# 取前100个高频词
data =[(word, count)for word, count in top_words]
w =(
WordCloud().add("", data))
w.render_notebook()
data = df['Faculty'].value_counts()[:10]
pie =(
Pie().add('',[list(z)for z inzip(data.index, data.values)],
label_opts=opts.LabelOpts(formatter="{b}: {c} ({d}%)")).set_global_opts(title_opts=opts.TitleOpts(title="科室分布TOP10")))
pie.render_notebook()