在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 數(shù)據(jù)分析&挖掘/ Pandas選項和自定義
Pandas教程
Pandas注意事項&竅門
Pandas IO工具
Pandas重建索引
Pandas稀疏數(shù)據(jù)
Pandas時間差(Timedelta)
Pandas聚合
Pandas字符串和文本數(shù)據(jù)
Pandas分類數(shù)據(jù)
Pandas索引和選擇數(shù)據(jù)
Pandas基本功能
Pandas系列
Pandas數(shù)據(jù)幀(DataFrame)
Pandas日期功能
Pandas缺失數(shù)據(jù)
Pandas與SQL比較
Pandas迭代
Pandas合并/連接
Pandas選項和自定義
Pandas級聯(lián)
Pandas可視化
Pandas數(shù)據(jù)結(jié)構(gòu)
Pandas環(huán)境安裝配置
Pandas統(tǒng)計函數(shù)
Pandas窗口函數(shù)
Pandas面板(Panel)
Pandas排序
Pandas函數(shù)應(yīng)用
Pandas快速入門
Pandas描述性統(tǒng)計
Pandas分組(GroupBy)

Pandas選項和自定義

Pandas提供API來自定義其行為的某些方面,大多使用來顯示。

API由五個相關(guān)函數(shù)組成。它們分別是 -

  • get_option()
  • set_option()
  • reset_option()
  • describe_option()
  • option_context()

現(xiàn)在來了解函數(shù)是如何工作的。

get_option(param)

get_option(param)需要一個參數(shù),并返回下面輸出中給出的值 -

get_option需要一個參數(shù),并返回下面輸出中給出的值 -

display.max_rows

顯示默認(rèn)值。解釋器讀取此值并顯示此值作為顯示上限的行。

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

執(zhí)行上面示例代碼,得到以下結(jié)果 -

display.max_rows =  60

display.max_columns

顯示默認(rèn)值,解釋器讀取此值并顯示此值作為顯示上限的行。

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

執(zhí)行上面示例代碼,得到以下結(jié)果 -

display.max_columns =  20

這里,6020是默認(rèn)配置參數(shù)值。

set_option(param,value)

set_option需要兩個參數(shù),并將該值設(shè)置為指定的參數(shù)值,如下所示:

display.max_rows

使用set_option(),可以更改要顯示的默認(rèn)行數(shù)。

import pandas as pd

print ("before set display.max_rows = ", pd.get_option("display.max_rows")) 

pd.set_option("display.max_rows",80)
print ("after set display.max_rows = ", pd.get_option("display.max_rows"))

執(zhí)行上面示例代碼,得到以下結(jié)果 -

before set display.max_rows =  60
after set display.max_rows =  80

display.max_columns

使用set_option(),可以更改要顯示的默認(rèn)行數(shù)。

import pandas as pd

print ("before set display.max_columns = ", pd.get_option("display.max_columns")) 

pd.set_option("display.max_columns",32)
print ("after set display.max_columns = ", pd.get_option("display.max_columns"))

執(zhí)行上面示例代碼,得到以下結(jié)果 -

before set display.max_columns =  20
after set display.max_columns =  32

reset_option(param)

reset_option接受一個參數(shù),并將該值設(shè)置為默認(rèn)值。

display.max_rows

使用reset_option(),可以將該值更改回顯示的默認(rèn)行數(shù)。

import pandas as pd

pd.set_option("display.max_rows",32)
print ("after set display.max_rows = ", pd.get_option("display.max_rows")) 

pd.reset_option("display.max_rows")
print ("reset display.max_rows = ", pd.get_option("display.max_rows"))

執(zhí)行上面示例代碼,得到以下結(jié)果 -

after set display.max_rows =  32
reset display.max_rows =  60

describe_option(param)

describe_option打印參數(shù)的描述。

display.max_rows

使用reset_option(),可以將該值更改回顯示的默認(rèn)行數(shù)。

import pandas as pd

pd.describe_option("display.max_rows")

執(zhí)行上面示例代碼,得到以下結(jié)果 -

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]

option_context()

option_context上下文管理器用于臨時設(shè)置語句中的選項。當(dāng)退出使用塊時,選項值將自動恢復(fù) -

display.max_rows
使用option_context(),可以臨時設(shè)置該值。

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"))

執(zhí)行上面示例代碼,得到以下結(jié)果 -

10
10

請參閱第一和第二個打印語句之間的區(qū)別。第一個語句打印由option_context()設(shè)置的值,該值在上下文中是臨時的。在使用上下文之后,第二個打印語句打印配置的值。

常用參數(shù),請參考下表 -

編號 參數(shù) 描述
1 display.max_rows 要顯示的最大行數(shù)
2 display.max_columns 要顯示的最大列數(shù)
3 display.expand_frame_repr 顯示數(shù)據(jù)幀以拉伸頁面
4 display.max_colwidth 顯示最大列寬
5 display.precision 顯示十進(jìn)制數(shù)的精度