pandas 在 Python 中使用 data.info() 显示所有信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43427564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 03:24:06  来源:igfitidea点击:

Display all informations with data.info() in Python

pythonpandas

提问by brad_curtis

I would display all informations of my data frame which contains more than 100 columns with .info() from panda but it won't :

我会显示我的数据框的所有信息,其中包含来自Pandas的 .info() 超过 100 列,但它不会:

data_train.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 85529 entries, 0 to 85528
Columns: 110 entries, ID to TARGET
dtypes: float64(40), int64(19), object(51)
memory usage: 71.8+ MB

I would like it displays like this :

我希望它显示如下:

data_train.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10886 entries, 0 to 10885
Data columns (total 12 columns):
datetime      10886 non-null object
season        10886 non-null int64
holiday       10886 non-null int64
workingday    10886 non-null int64
weather       10886 non-null int64
temp          10886 non-null float64
atemp         10886 non-null float64
humidity      10886 non-null int64
windspeed     10886 non-null float64
casual        10886 non-null int64
registered    10886 non-null int64
count         10886 non-null int64
dtypes: float64(3), int64(8), object(1)
memory usage: 1020.6+ KB

But the problem seems to be the high number of columns from my previous data frame.

但问题似乎是我以前的数据框中的列数过多。

Is there a way to fix that ?

有没有办法解决这个问题?

Thank You.

谢谢你。

@James

@詹姆士

It works but it doesn't show if there are non null values (NaN)

它有效,但不显示是否有非空值(NaN)

data_train.info(verbose=True)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 85529 entries, 0 to 85528
Data columns (total 110 columns):
ID           int64
COD_INSEE    float64
COD_IRIS     float64
C1           object
C2           object
C3           object
C4           object
C5           int64
C6           int64
C7           int64
C8           object
C9           object
C10          int64
C11          int64
C12          object
C13          object
C14          object
C15          int64
C16          int64
C17          int64
C18          int64
C19          int64
S1           float64
S2           int64
S3           object
S4           object
S5           object
S6           object
S7           object
S8           int64
S9           int64
S10          int64
S11          int64
S12          int64
Q1           object
Q2           object
Q3           object
Q4           float64
Q5           int64
Q6           float64
Q7           object
Q8           float64
Q9           float64
Q10          object
Q11          object
Q12          object
Q13          float64
Q14          float64
Q15          float64
Q16          object
Q17          float64
Q18          float64
Q19          float64
Q20          float64
Q21          float64
Q22          float64
Q23          float64
Q24          float64
Q25          float64
Q26          float64
Q27          float64
Q28          object
Q29          object
Q30          float64
Q31          float64
Q32          object
Q33          float64
Q34          object
Q35          float64
Q36          object
Q37          float64
Q38          float64
Q39          object
Q40          float64
Q41          float64
Q42          float64
Q43          float64
Q44          float64
Q45          float64
Q46          float64
Q47          float64
Q48          float64
Q49          float64
Q50          float64
Q51          float64
Q52          float64
Q53          object
Q54          object
Q55          object
Q56          object
Q57          object
Q58          object
Q59          object
Q60          object
Q61          object
Q62          object
Q63          object
Q64          object
Q65          object
Q66          object
Q67          object
Q68          object
Q69          object
Q70          object
Q71          object
Q72          object
Q73          object
Q74          object
Q75          object
TARGET       int64
dtypes: float64(40), int64(19), object(51)
memory usage: 71.8+ MB

回答by James

You can pass optional arguments verbose=Trueand null_counts=Trueto the .info()method to output information for all of the columns

你可以通过可选的参数verbose=True,并null_counts=True.info()方法输出信息的所有列

data_train.info(verbose=True, null_counts=True)