Help us understand the problem. What is going on with this article?

pandasのoption設定変更方法

More than 1 year has passed since last update.

表示行数の設定

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%
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away