【问题标题】:Print all the rows in the table打印表格中的所有行
【发布时间】:2017-04-22 04:27:14
【问题描述】:

我想打印表格中的所有行。 “stat_data”列表有 323 个我想在控制台上打印的项目。

使用下面的代码来做到这一点。

from astropy.table import Table, Column
t = Table(rows=stat_data, names=('Redacted Term', 'Length', 'File', 'Type'))
print(t)

但它只打印更少的行,而不是全部。帮我打印所有行。

以上代码的输出如下

    Redacted Term Length             File              Type
    ------------- ------ ---------------------------- ------
    Trump      5                       1.html  names
    4909090909     10 otherfiles/sample-output.txt phones
    3235294117     10 otherfiles/sample-output.txt phones
    5957446808     10 otherfiles/sample-output.txt phones
    8518518518     10 otherfiles/sample-output.txt phones
    3255813953     10 otherfiles/sample-output.txt phones
    5227272727     10 otherfiles/sample-output.txt phones
    3076923076     10 otherfiles/sample-output.txt phones
    0555555555     10 otherfiles/sample-output.txt phones
    5384615384     10 otherfiles/sample-output.txt phones
    4210526315     10 otherfiles/sample-output.txt phones
    7777777777     10 otherfiles/sample-output.txt phones
    3181818181     10 otherfiles/sample-output.txt phones
    5869565217     10 otherfiles/sample-output.txt phones
    1153846153     10 otherfiles/sample-output.txt phones
    4347826086     10 otherfiles/sample-output.txt phones
    2043010752     10 otherfiles/sample-output.txt phones
    8260869565     10 otherfiles/sample-output.txt phones
    6315789473     10 otherfiles/sample-output.txt phones
    4583333333     10 otherfiles/sample-output.txt phones
      ...    ...                          ...    ...
    William      7             otherfiles/a.txt  names
    Mastrosimone     12             otherfiles/a.txt  names
    William      7             otherfiles/a.txt  names
     Tell      4             otherfiles/a.txt  names
    Oveture      7             otherfiles/a.txt  names
    Gioachino      9             otherfiles/a.txt  names
    Rossini      7             otherfiles/a.txt  names
    Oklahoma      8             otherfiles/a.txt places
    Sydney      6             otherfiles/a.txt places
    Dallas      6             otherfiles/a.txt places
    Texas      5             otherfiles/a.txt places
      San      3             otherfiles/a.txt places
    Fransisco      9             otherfiles/a.txt places
      USA      3             otherfiles/a.txt places
    Cupertino      9             otherfiles/a.txt places
    Cupertino      9             otherfiles/a.txt places
       CA      2             otherfiles/a.txt places
    Vinayak      7             otherfiles/2.txt  names
    Sudhindra      9             otherfiles/3.txt  names
    Sudhindra      9             otherfiles/3.txt  names
    Length = 323 rows

【问题讨论】:

标签: python rows entropy


【解决方案1】:

pprint 方法允许在不截断的情况下打印 astropy Table 中的多行。例如,如果blat 是一个 Table 并且您想要打印 100 行:

nlines = 100
blat.pprint(nlines) 

打印所有行:

nlines = len(blat) + 2
blat.pprint(nlines) 

通常需要+2 来说明标题行。

【讨论】:

    【解决方案2】:

    遍历一个表并打印每一行是一种解决 Python 有时应用于长输出的截断的简单方法。

    鉴于t 是来自astropy.tableTable,试试这个:

    for row in t:
        print(row.as_void())
    

    这里,rowRow objectas_void() 生成该行的原始数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 2023-01-04
      相关资源
      最近更新 更多