【问题标题】:How can i display all columns in google colab?如何在 google colab 中显示所有列?
【发布时间】:2023-01-14 11:25:35
【问题描述】:

我想在包含空值的 google colab 中显示数据框的所有列。 Colab 显示了一些列并在中间显示了点,并继续再次显示列到最后几列。

如何显示所有列?

【问题讨论】:

  • 你能试试data.columnsprint(data.columns)吗?
  • 好吧,它显示了所有列索引,但我也想显示空值

标签: python google-colaboratory


【解决方案1】:

这应该有效:

import pandas as pd 
pd.set_option('display.max_columns', None)

【讨论】:

    【解决方案2】:

    如果你是用pandas操作数据,想显示所有列,请参考Haddock-san's answer

    但是,如果要显示由 df.isnull.sum() 或其他方式产生的所有行,可以使用 pd.set_option('display.max_rows', None) 来实现所需的输出:

    例子:

    import pandas as pd 
    import numpy as np
    
    # generate reproducible data
    rng = np.random.default_rng(12)
    
    df = pd.DataFrame([rng.choice(a=[5, None], size=100)])
    print(df.isnull().sum())
    

    输出:

    0     1
    1     0
    2     1
    3     1
    4     0
         ..
    95    1
    96    1
    97    1
    98    1
    99    1
    Length: 100, dtype: int64
    

    解决方案:

    import pandas as pd 
    pd.set_option('display.max_rows', None)
    
    # remaining code from above to count the number
    # of missing elements in each column in df
    

    输出:

    0     1
    1     0
    2     1
    3     1
    4     0
    5     0
    6     0
    7     0
    8     1
    9     0
    10    0
    11    0
    12    1
    13    1
    14    1
    15    0
    16    0
    17    1
    18    0
    19    1
    20    1
    21    0
    22    0
    23    1
    24    0
    25    0
    26    1
    27    0
    28    0
    29    0
    30    0
    31    0
    32    1
    33    0
    34    1
    35    1
    36    0
    37    0
    38    1
    39    0
    40    1
    41    1
    42    1
    43    1
    44    0
    45    1
    46    1
    47    1
    48    0
    49    0
    50    1
    51    1
    52    0
    53    1
    54    0
    55    1
    56    1
    57    0
    58    1
    59    0
    60    1
    61    1
    62    1
    63    1
    64    0
    65    1
    66    1
    67    0
    68    1
    69    0
    70    0
    71    1
    72    1
    73    0
    74    0
    75    1
    76    1
    77    0
    78    0
    79    1
    80    0
    81    0
    82    0
    83    0
    84    1
    85    0
    86    1
    87    1
    88    1
    89    1
    90    0
    91    1
    92    1
    93    1
    94    1
    95    1
    96    1
    97    1
    98    1
    99    1
    dtype: int64
    

    【讨论】:

    • OP 要求列,而不是行。
    • @Haddock-san 你是对的 - 希望编辑后的答案对 OP 也有帮助。
    猜你喜欢
    • 2021-11-23
    • 2019-03-18
    • 2022-01-14
    • 2020-10-10
    • 2020-08-31
    • 2020-07-21
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    相关资源
    最近更新 更多