Python-pandas-options-and-customization
Python Pandas-オプションとカスタマイズ
パンダは、その動作のいくつかの側面をカスタマイズするためのAPIを提供し、ディスプレイが主に使用されています。
APIは、5つの関連する機能で構成されています。 彼らは-
- get_option()
- set_option()
- reset_option()
- describe_option()
- option_context()
関数がどのように動作するかを理解しましょう。
get_option(param)
get_optionは単一のパラメータを取り、以下の出力で与えられた値を返します-
display.max_rows
値のデフォルト数を表示します。 通訳者はこの値を読み取り、表示する上限としてこの値を持つ行を表示します。
import pandas as pd
print pd.get_option("display.max_rows")
その*出力*は次のとおりです-
60
display.max_columns
値のデフォルト数を表示します。 通訳者はこの値を読み取り、表示する上限としてこの値を持つ行を表示します。
import pandas as pd
print pd.get_option("display.max_columns")
その*出力*は次のとおりです-
20
ここで、60および20はデフォルトの構成パラメーター値です。
set_option(param、value)
set_optionは2つの引数を取り、以下に示すようにパラメータに値を設定します-
display.max_rows
- set_option()*を使用して、表示するデフォルトの行数を変更できます。
import pandas as pd
pd.set_option("display.max_rows",80)
print pd.get_option("display.max_rows")
その*出力*は次のとおりです-
80
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* は引数を取り、値をデフォルト値に戻します。
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* は引数の説明を出力します。
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]
option_context()
option_contextコンテキストマネージャーは、* withステートメント*でオプションを一時的に設定するために使用されます。 with block を終了すると、オプション値は自動的に復元されます-
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
1番目と2番目のprintステートメントの違いを参照してください。 最初のステートメントは、 with_context 自体の内部で一時的な* option_context()によって設定された値を出力します。 *with context の後、2番目のprintステートメントは設定された値を出力します。
よく使用されるパラメーター
Sr.No | Parameter & Description |
---|---|
1 |
display.max_rows 表示する最大行数を表示します |
2 |
2 display.max_columns 表示する列の最大数を表示します |
3 |
display.expand_frame_repr ページをストレッチするためのデータフレームを表示します |
4 |
display.max_colwidth 最大列幅を表示します |
5 |
display.precision 10進数の精度を表示します |