LoginSignup
3
3

More than 5 years have passed since last update.

pandasのoption設定変更方法

Posted at

表示行数の設定

python3
import pandas as pd
import numpy as np
df=pd.DataFrame(np.random.rand(20,20)) #20行x20列のDataFrameを作成
pd.options.display.max_rows=5 #最大表示行数=5に設定
pd.options.display.max_columns=5 #最大表示列数=5に設定
df
出力結果
          0         1     ...           18        19
0   0.680790  0.653840    ...     0.136195  0.548428
1   0.544310  0.385327    ...     0.292293  0.043041
..       ...       ...    ...          ...       ...
18  0.122189  0.928378    ...     0.905592  0.159815
19  0.052095  0.079974    ...     0.559600  0.287442

小数点以下の表示桁数の制御

python3
pd.options.display.float_format='{:.2f}'.format #小数点以下2桁まで表示する
df
出力結果
     0    1  ...    18   19
0  0.68 0.65 ...  0.14 0.55
1  0.54 0.39 ...  0.29 0.04
..  ...  ... ...   ...  ...
18 0.12 0.93 ...  0.91 0.16
19 0.05 0.08 ...  0.56 0.29
python3
pd.options.display.float_format='{:.2%}'.format #%表示にして、小数点以下2桁まで表示する
df
       0      1   ...       18     19
0  68.08% 65.38%  ...   13.62% 54.84%
1  54.43% 38.53%  ...   29.23%  4.30%
..    ...    ...  ...      ...    ...
18 12.22% 92.84%  ...   90.56% 15.98%
19  5.21%  8.00%  ...   55.96% 28.74%
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3