• 数据分析必备:一步步教你如何用Pandas做数据分析(11)


    1、Pandas 自定义选项

    Pandas 自定义选项操作实例
    Pandas因为提供了API来自定义行为,所以被广泛使用。
    自定义API中有五个相关功如下:
    get_option()
    set_option()
    reset_option()
    describe_option()
    option_context()
    下面我们一起了解下这些方法。

    1.1、get_option(param)

    get_option接受一个参数并输出以下值:
    display.max_rows
    显示默认值的数量。解释器读取该值,并以该值作为显示上限显示行。

    import pandas as pd
    print(pd.get_option("display.max_rows"))
    

    运行结果:

      60
    

    1.2、display.max_columns

    显示默认值的数量。解释器读取该值,并以该值作为显示上限显示行。

    import pandas as pd
    print(pd.get_option("display.max_columns"))
    

    运行结果:

    0
    

    此处,60和0是默认配置参数值。
    set_option(param,value)
    set_option接受两个参数并将值设置为参数,如下所示:

    1.3、display.max_rows

    使用set_option(),我们可以更改要显示的默认行数。

    import pandas as pd
    pd.set_option("display.max_rows",80)
    print(pd.get_option("display.max_rows"))
    

    运行结果:

    80
    

    1.4、display.max_columns

    使用set_option(),我们可以更改要显示的默认行数。

    import pandas as pd
     pd.set_option("display.max_columns",30)
     print(pd.get_option("display.max_columns"))
    

    运行结果:

    30
    

    reset_option(param)
    reset_option 接受一个参数并将其设置回默认值。

    1.5、display.max_rows

    使用reset_option(),我们可以将值更改回要显示的默认行数。

    import pandas as pd
    pd.reset_option("display.max_rows")
    print(pd.get_option("display.max_rows"))
    

    运行结果:

       60
    

    describe_option(param)
    describe_option 打印参数的描述

    1.6、display.max_rows

    使用reset_option(),我们可以将值更改回要显示的默认行数。

     import pandas as pd
     pd.describe_option("display.max_rows")
    

    运行结果:

    display.max_rows : int
        If max_rows is exceeded, switch to truncate view. Depending on
        `large_repr`, objects are either centrally truncated or printed as
        a summary view. 'None' value means unlimited.
    
        In case python/IPython is running in a terminal and `large_repr`
        equals 'truncate' this can be set to 0 and pandas will auto-detect
        the height of the terminal and print a truncated object which fits
        the screen height. The IPython notebook, IPython qtconsole, or
        IDLE do not run in a terminal and hence it is not possible to do
        correct auto-detection.
        [default: 60] [currently: 60]
    

    1.7、option_context()

    option_context上下文管理器用于临时设置with语句中的选项。当您退出with块时,选项值会自动恢复。
    display.max_rows
    使用option_context(),我们可以临时设置值。

    import pandas as pd
    with pd.option_context("display.max_rows", 10):
        print(pd.get_option("display.max_rows"))
        print(pd.get_option("display.max_rows"))
    

    运行结果:

    10
    10
    

    请参阅第一个和第二个打印语句之间的差异。第一条语句打印由option_context()设置的值,该值在with上下文本身中是临时的。在with上下文之后,第二个print语句打印配置的值。

    1.8、Frequently used 参数

    在这里插入图片描述

  • 相关阅读:
    应用开发平台集成工作流系列之16——办理意见设计与实现
    数字图像处理(入门篇)三 灰度化
    【C语言经典100题#4】判断三角形
    .NET微服务系列之Saga分布式事务案例实践
    使用百度EasyDL实现银行客户流失预测
    c语言:倒序4位数
    kali 虚拟攻击模式
    详细描述 Java 虚拟机(JVM)的内存模型,包括堆、栈、方法区、程序计数器等部分,以及它们各自的作用和相互关系。
    Java并发面试题:(七)ThreadLocal原理和内存泄漏
    [时间序列预测]基于BP、RNN、LSTM、CNN-LSTM算法多特征(多影响因素)用电负荷预测[保姆级手把手教学]
  • 原文地址:https://blog.csdn.net/qq_45746668/article/details/139301317