在使用dataframe时遇到datafram在列太多的情况下总是自动换行显示的情况,导致数据阅读困难,效果如下:
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randn(1, 20))
print(df)
显示效果:
0 1 2 3 4 5 6 \
0 -1.193428 -0.870381 -0.970323 -1.062275 1.227282 -3.016298 -0.587623
7 8 9 10 11 12 13 \
0 -0.608017 -0.006382 0.275454 -0.073537 1.217392 -0.12844 -1.228424
14 15 16 17 18 19
0 -1.153452 0.191372 0.582537 0.503437 -2.263716 -0.529881
height has been deprecated.
解决方法:
在代码中设置显示的长宽等,如下代码示例:
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
# pd.set_option('display.height', 1000)
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
df = pd.DataFrame(np.random.randn(1, 20))
print(df)
结果:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
0 -1.156806 1.369516 -1.168495 -1.433812 -0.018393 0.905978 1.023163 0.837558 0.308197 -1.517295 -0.613672 0.520296 -1.767314 1.4455 0.257171 -0.254236 1.172506 0.915582 -1.304788 0.774369