zoukankan      html  css  js  c++  java
  • 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 双向队列,可以从左边弹出,右边加入

  • 相关阅读:
    微信小程序自定义分享图片
    rtop:一个通过 SSH 监控远程主机的交互式工具【转】
    mysql双主+keepalived【转】
    诡异的Linux磁盘空间被占用问题,根目录满了,df和du占用不一样【转】
    linux磁盘空间查看inode
    python数据库操作
    Jenkins 安装及使用
    编程入门python之定义函数【转】
    grep和sed匹配多个字符关键字的用法
    linux 如何删除文件夹下面的文件和文件夹,只保留两个文件
  • 原文地址:https://www.cnblogs.com/GavinSimons/p/11069917.html
Copyright © 2011-2022 走看看