python库用杂记

pandas

# 将pd类data数据中所有0转化成None
for col in 特征列表:
	data[col].replace([0],[None],inplace=True)

data_drop=data.dropna()
#删除后的数据和原数据的均值变化:
ax=((data_drop.mean()-data.mean())/data.mean()).plot(kind="bar",title="change in mean")
ax.set_ylabel("% change")

data.hist(figsize=(15,15),share=True)# 直方图,share表示是否共享横轴

numpy

test=np.loadtxt("路径"
				,delimiter=","
				,dtype="int"
				,unpack=True)
				
a=[1,2,3,4,5,32,34,34,4,3,]
np.argmax(a,axis=0)
np.unique(y)

matplotlib

创建子图架构函数

fig=plt.figure(figsize=(8,8))
ax=fig.add_subplot(111)
ax.set_ylim([2,6])
ax.set_title("fasf")#子图标题
ax.plot([1,2,3,4],[1,2,3,4])
ax.set_xlabel("x_zhou",loc="right")#横轴label
ax.set_ylabel("y_zhou",loc="top")#纵轴label
# ax.set_xticklabels([])#横轴数值
# ax.set_yticklabels([])

# 格式显示位置自定义
plt.tight_layout()
fig.subplots_adjust(left=None, bottom=None, right=None, top=None
				,wspace=None
				,hspace=None)

在这里插入图片描述

fill_betweenx填充

ax.fill_betweenx([1,2,3,4], # 纵向位置
				[0.4,0.8,0.1,0.5], # 横向长度
				facecolor="red", 
				alpha=0.7
				)

在这里插入图片描述

axvspan纵向填充

ax.axvspan(xmin=2
		   ,xmax=3
		   ,ymin=0
		   ,ymax=1
		   #ymin,ymax为[0,1]中数
		   ,color="red"
		   ,alpha=0.6)
#添加颜色在横坐标为2到3之间

在这里插入图片描述

boxplot箱线图

fig = plt.figure(figsize=(8, 8), dpi=200)
fig.add_subplot(111)
ax.boxplot([1,2,3,2,12,2,1,12,12,1,2,1,2,1,3,4,32,5,34,])
plt.xlabel('MonthlyCharges')

在这里插入图片描述

histplot直方图和核密度函数

import seaborn as sns
fig = plt.figure(figsize=(16, 6), dpi=200)
fig.add_subplot(121)
sns.histplot(数据, kde=True)
fig.add_subplot(122)
sns.histplot(tcc['TotalCharges'], kde=True)

在这里插入图片描述

countplot柱状图和堆叠图

fig = plt.figure(figsize=(16, 6), dpi=200)
fig.add_subplot(121)
# 柱状图
sns.countplot(x=分类标签,hue=目标(统计)便签,data=pandas数据,palette="Blues", dodge=True)
plt.xlabel("Gender")
plt.title("Churn by Gender")
fig.add_subplot(122)

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「 25' h 」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值