场景
在利用Pandas
等进行大量数据处理时,为了直观,经常会打印数据。但由于数据量大,pycharm
打印不完全, 中间有省略号,看起来十分不爽。如下:
A B C D
2018-10-01 0.068220 0.159656 1.087268 -0.246828
2018-10-02 -0.141314 -1.401174 0.103092 0.255756
2018-10-03 -0.040068 -1.430353 1.055588 0.462923
C D E F
2018-10-02 -0.554048 0.070269 -1.334605 2.589841
2018-10-03 -0.151967 -1.098840 -0.397481 -0.750993
2018-10-04 -0.032707 0.833424 -0.259885 0.984697
A B C ... D E F
2018-10-01 0.068220 0.159656 1.087268 ... NaN NaN NaN
2018-10-02 -0.141314 -1.401174 0.103092 ... 0.070269 -1.334605 2.589841
2018-10-03 -0.040068 -1.430353 1.055588 ... -1.098840 -0.397481 -0.750993
[3 rows x 8 columns]
Process finished with exit code 0
解决方案
如果你也用pandas
模块,则可以添加如下三行代码:
# 核心代码,设置显示的最大列、宽等参数,消掉打印不完全中间的省略号
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)
通常的做法是在,导入模块后,就进行设置这些参数,如下:
import pandas as pd
import numpy as np
# 核心代码,设置显示的最大列、宽等参数,消掉打印不完全中间的省略号
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)
这样配置后,就可以消掉打印不完全中间的省略号了,打印结果:
A B C D
2018-10-01 -0.902319 1.094991 0.362774 -0.711619
2018-10-02 -0.468856 0.697782 -0.791415 -0.257628
2018-10-03 -0.172319 -0.217480 -0.590856 1.686836
C D E F
2018-10-02 -0.224458 0.884790 0.487091 0.713386
2018-10-03 1.045041 1.007130 0.118781 0.833019
2018-10-04 -0.784525 -0.299482 -0.652232 1.497122
A B C D C D E F
2018-10-01 -0.902319 1.094991 0.362774 -0.711619 NaN NaN NaN NaN
2018-10-02 -0.468856 0.697782 -0.791415 -0.257628 -0.224458 0.88479 0.487091 0.713386
2018-10-03 -0.172319 -0.217480 -0.590856 1.686836 1.045041 1.00713 0.118781 0.833019
Process finished with exit code 0