如何从命令行对齐pandas的输出?

时间:2017-07-10 08:57:18

标签: python excel pandas

我想在 Windows 上的命令行提示符中对齐pandas输出。

这是我的代码:

# -*- coding: utf-8 -*-
# -*- coding: gbk -*-
import pandas as pd
import numpy as np
import sys
import re
import os

script_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(script_dir ) # change to the path that you already know

# dfclient = pd.read_excel(u"ClientManagerNumber.xlsx")
# print(dfclient)
df = pd.read_excel(u"总表-4.26.xlsm")

for i in range(1,18):
    # mask = dfclient[u'序号'] == i
    DataRes = df[[ u"客户"]][df[u'编码'] >= ( i * 100 )][df[u'编码'] < (( i + 1) * 100 )][~df[u'客户'].isnull()].drop_duplicates(subset=[u'客户'], keep='first')
    if not DataRes.empty:
        # print(dfclient[u'姓名'][mask].to_string( index = False))
        print(DataRes.to_string(index = False, header = False))

这是我的excel文件,如

enter image description here

命令行中的输出如下:

enter image description here

我从Stack Overflow获得了2个相关的答案

Stack Overflow link1

帖子中有一条由 monospace 字体引起的评论。 我使用cmder作为提示,它已经设置了等宽

enter image description here

Stack Overflow link2

这篇文章设置了像df.style.set_properties(**{'text-align': 'left'})这样的选项,但它对我也不起作用。

那么如何在命令行中对齐输出。我想知道为什么测试 test2 没有对齐?如果我复制excel文件中的test或test2行并将其粘贴为新行 test3 ,例如。 test3行仍未对齐。

这是我的Excel文件link

0 个答案:

没有答案