FEATURED · 精选文章

Python打卡第7天

发布时间 / 2026/8/19 23:55:53
来源 / 创域科博编辑部
栏目 / 资讯中心
Python打卡第7天 浙大疏锦行作业01020304050607080910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970importpandas as pdheartdfpd.read_csv(Python打卡训练营\Python打卡训练营\python60-days-challenge-master\heart.csv)# 先看数据长什么样print(heartdf.head())print(heartdf.shape)print(heartdf.columns)print(heartdf.dtypes)print(heartdf.info())# 体检看看有无异常值print(heartdf.describe(percentiles[.25, .5, .75, .9]))# 检查缺失值有则进行清洗、填补print(heartdf.isnull().sum())missing_ratioheartdf.isnull().sum()/len(heartdf)*100print(missing_ratio)# 对于非分类的特征画图查看是否有异常值importmatplotlib.pyplot as pltimportseaborn as snsimportmathcategorical_features[sex,cp,fbs,restecg,exang,slope,ca,thal]labeltargetcontinuous_features[colforcolinheartdf.columnsifcolnotincategorical_featuresandcol !label]n_cols3n_rowsmath.ceil(len(continuous_features)/n_cols)fig, axesplt.subplots(n_rows,n_cols,figsize(15,4*n_rows))# 转成一维方便遍历axesaxes.flatten()fori, colinenumerate(continuous_features):sns.boxplot(xheartdf[col],axaxes[i])axes[i].set_title(fBoxplot of {col})# 如果最后一行没有填满把多余子图删掉forjinrange(len(continuous_features),len(axes)):fig.delaxes(axes[j])plt.tight_layout()plt.show()# 后续还要做标准化防止数据泄露划分数据集时间序列还需要做滑动窗口
RELATED — 相关阅读

相关资讯

LATEST — 最新资讯

最新发布

TODAY — 本日精选

新闻

WEEKLY — 本周精选

新闻

MONTHLY — 本月精选

新闻