在Python中正确缩进表输出

时间:2018-10-14 01:22:38

标签: python python-3.x

我正在使用基本的python编辑器(Wing 101)。当打印出表格(用于分析)时,我弄乱了行和列。请看下面:

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import seaborn as sns
import os
import matplotlib.pyplot as plt         


#STEP 2: Access the Data files
data = pd.read_csv('data.csv', index_col=0)
data.sort_values(['Year', "Happiness Score"], ascending=[True, False], inplace=True)
#diplay first 10 rows
data.head(10)

我得到了这个垃圾:

[evaluate World Happness Data Analysis.py]
data.head(10)
         Country                     Region  ...   Dystopia Residual  Year
141  Switzerland             Western Europe  ...             2.51738  2015
60       Iceland             Western Europe  ...             2.70201  2015
38       Denmark             Western Europe  ...             2.49204  2015
108       Norway             Western Europe  ...             2.46531  2015
25        Canada              North America  ...             2.45176  2015
46       Finland             Western Europe  ...             2.61955  2015
102  Netherlands             Western Europe  ...             2.46570  2015
140       Sweden             Western Europe  ...             2.37119  2015
103  New Zealand  Australia and New Zealand  ...             2.26425  2015
6      Australia  Australia and New Zealand  ...             2.26646  2015

[10 rows x 12 columns]

实际上,上面看起来合理。但是在Python shell中,它完全是一团糟。 here's the actual output

我的问题:如何获得带有单元格边框的表格打印输出?

1 个答案:

答案 0 :(得分:1)

更改Python Shell的字体设置。使用某些等宽字体。最常见的选择是“新快递”或“新快递”。