Python pands和matplotlib常用命令

一、pandas常用函数

df.sort_values()——按行列数据排序
df.sort_index()——按行列标签排序
df.duplicated()——判断重复数据
df.drop_duplicates()——去重
df.reset_index()——重新设置索引
df.set_index()——把某列设置为索引
df.rename(columns={})——修改列名
df = df[~df[]==XX]——"~"为取反
series.isin(list)——series单个数据是否在list中
series.str.replace('', '')——series字符替换
series.str.contains('xx')——series中是否包含"xx"字符,"xx"可为"^[92]"或[0-9]
df.apply(func)——应用自定义函数,底层用C运算,速度快
df.apply(lambda x: x.sum())——匿名函数
df.empty——df是否为空
df.fillna('')——缺失值填充
df.loc[xx, :]——取出某行全部数据
pd.concat()——df拼接
df.head(n)——展示前n行
df.T——df转置
df.corr()——计算相关系数
df.to_csv(file, encoding=)——保存文件
pd.read_csv(file, index_col=,encoding=)——读取文件
pd.read_excel(file, sheet_name, index_col,encoding)

pandas中excel操作
writer = pd.ExcelWriter(filePath)
df.to_excel(writer,sheet_name=, encoding=)
writer.save()

二、matplotlib常用操作

plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
plt.rcParams['figure.figsize'] = (16, 9) # 分辨率为16:9
plt.cla()——清除原有图像
plt.grid(b=None, which='major', axis='both')——网格设置
plt.savefig()——保存图片
子图1
fig, ax = plt.subplots()——生成子图
ax.xaxis.set_major_locator(ticker.MultipleLocator(5))——定义子图横坐标主刻度
ax.xaxis.set_minor_locator(ticker.MultipleLocator(1))——定义子图横坐标次刻度
ax.xaxis.grid(True, which='minor')——x坐标轴的网格使用主刻度 # 网格使用次坐标
ax.tick_params(which='minor', direction='in')
子图2
ax1 = plt.subplot2grid((2, 1), (0, 0), rowspan=1, colspan=1)
ax2 = plt.subplot2grid((2, 1), (1, 0), rowspan=1, colspan=1)
plt.setp(ax1.get_xticklabels(), visible=False) # 上边子图隐藏x轴坐标
plt.subplots_adjust(hspace=0.1)

三、其他模块

1、collections.deque 双向队列,可以从左边弹出,右边加入

转载于:https://www.cnblogs.com/GavinSimons/p/11069917.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值