1
1
import sys
2
+ from typing import IO , Optional , Union
2
3
3
4
from pandas ._config import get_option
4
5
6
+ from pandas ._typing import FrameOrSeries
7
+
5
8
from pandas .io .formats import format as fmt
6
9
from pandas .io .formats .printing import pprint_thing
7
10
@@ -11,32 +14,33 @@ def _put_str(s, space):
11
14
12
15
13
16
def info (
14
- data , verbose = None , buf = None , max_cols = None , memory_usage = None , null_counts = None
17
+ data : FrameOrSeries ,
18
+ verbose : Optional [bool ] = None ,
19
+ buf : Optional [IO [str ]] = None ,
20
+ max_cols : Optional [int ] = None ,
21
+ memory_usage : Optional [Union [bool , str ]] = None ,
22
+ null_counts : Optional [bool ] = None ,
15
23
) -> None :
16
24
"""
17
- Print a concise summary of a DataFrame .
25
+ Print a concise summary of a %(klass)s .
18
26
19
- This method prints information about a DataFrame including
20
- the index dtype and column dtypes , non-null values and memory usage.
27
+ This method prints information about a %(klass)s including
28
+ the index dtype%(type_sub)s , non-null values and memory usage.
21
29
22
30
Parameters
23
31
----------
24
- data : DataFrame
25
- DataFrame to print information about.
32
+ data : %(klass)s
33
+ %(klass)s to print information about.
26
34
verbose : bool, optional
27
35
Whether to print the full summary. By default, the setting in
28
36
``pandas.options.display.max_info_columns`` is followed.
29
37
buf : writable buffer, defaults to sys.stdout
30
38
Where to send the output. By default, the output is printed to
31
39
sys.stdout. Pass a writable buffer if you need to further process
32
40
the output.
33
- max_cols : int, optional
34
- When to switch from the verbose to the truncated output. If the
35
- DataFrame has more than `max_cols` columns, the truncated output
36
- is used. By default, the setting in
37
- ``pandas.options.display.max_info_columns`` is used.
41
+ %(max_cols_sub)s
38
42
memory_usage : bool, str, optional
39
- Specifies whether total memory usage of the DataFrame
43
+ Specifies whether total memory usage of the %(klass)s
40
44
elements (including the index) should be displayed. By default,
41
45
this follows the ``pandas.options.display.memory_usage`` setting.
42
46
@@ -50,105 +54,23 @@ def info(
50
54
at the cost of computational resources.
51
55
null_counts : bool, optional
52
56
Whether to show the non-null counts. By default, this is shown
53
- only if the frame is smaller than
57
+ only if the %(klass)s is smaller than
54
58
``pandas.options.display.max_info_rows`` and
55
59
``pandas.options.display.max_info_columns``. A value of True always
56
60
shows the counts, and False never shows the counts.
57
61
58
62
Returns
59
63
-------
60
64
None
61
- This method prints a summary of a DataFrame and returns None.
65
+ This method prints a summary of a %(klass)s and returns None.
62
66
63
67
See Also
64
68
--------
65
- DataFrame.describe: Generate descriptive statistics of DataFrame
66
- columns.
67
- DataFrame.memory_usage: Memory usage of DataFrame columns.
69
+ %(see_also_sub)s
68
70
69
71
Examples
70
72
--------
71
- >>> int_values = [1, 2, 3, 4, 5]
72
- >>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']
73
- >>> float_values = [0.0, 0.25, 0.5, 0.75, 1.0]
74
- >>> df = pd.DataFrame({"int_col": int_values, "text_col": text_values,
75
- ... "float_col": float_values})
76
- >>> df
77
- int_col text_col float_col
78
- 0 1 alpha 0.00
79
- 1 2 beta 0.25
80
- 2 3 gamma 0.50
81
- 3 4 delta 0.75
82
- 4 5 epsilon 1.00
83
-
84
- Prints information of all columns:
85
-
86
- >>> df.info(verbose=True)
87
- <class 'pandas.core.frame.DataFrame'>
88
- RangeIndex: 5 entries, 0 to 4
89
- Data columns (total 3 columns):
90
- # Column Non-Null Count Dtype
91
- --- ------ -------------- -----
92
- 0 int_col 5 non-null int64
93
- 1 text_col 5 non-null object
94
- 2 float_col 5 non-null float64
95
- dtypes: float64(1), int64(1), object(1)
96
- memory usage: 248.0+ bytes
97
-
98
- Prints a summary of columns count and its dtypes but not per column
99
- information:
100
-
101
- >>> df.info(verbose=False)
102
- <class 'pandas.core.frame.DataFrame'>
103
- RangeIndex: 5 entries, 0 to 4
104
- Columns: 3 entries, int_col to float_col
105
- dtypes: float64(1), int64(1), object(1)
106
- memory usage: 248.0+ bytes
107
-
108
- Pipe output of DataFrame.info to buffer instead of sys.stdout, get
109
- buffer content and writes to a text file:
110
-
111
- >>> import io
112
- >>> buffer = io.StringIO()
113
- >>> df.info(buf=buffer)
114
- >>> s = buffer.getvalue()
115
- >>> with open("df_info.txt", "w",
116
- ... encoding="utf-8") as f: # doctest: +SKIP
117
- ... f.write(s)
118
- 260
119
-
120
- The `memory_usage` parameter allows deep introspection mode, specially
121
- useful for big DataFrames and fine-tune memory optimization:
122
-
123
- >>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6)
124
- >>> df = pd.DataFrame({
125
- ... 'column_1': np.random.choice(['a', 'b', 'c'], 10 ** 6),
126
- ... 'column_2': np.random.choice(['a', 'b', 'c'], 10 ** 6),
127
- ... 'column_3': np.random.choice(['a', 'b', 'c'], 10 ** 6)
128
- ... })
129
- >>> df.info()
130
- <class 'pandas.core.frame.DataFrame'>
131
- RangeIndex: 1000000 entries, 0 to 999999
132
- Data columns (total 3 columns):
133
- # Column Non-Null Count Dtype
134
- --- ------ -------------- -----
135
- 0 column_1 1000000 non-null object
136
- 1 column_2 1000000 non-null object
137
- 2 column_3 1000000 non-null object
138
- dtypes: object(3)
139
- memory usage: 22.9+ MB
140
-
141
- >>> df.info(memory_usage='deep')
142
- <class 'pandas.core.frame.DataFrame'>
143
- RangeIndex: 1000000 entries, 0 to 999999
144
- Data columns (total 3 columns):
145
- # Column Non-Null Count Dtype
146
- --- ------ -------------- -----
147
- 0 column_1 1000000 non-null object
148
- 1 column_2 1000000 non-null object
149
- 2 column_3 1000000 non-null object
150
- dtypes: object(3)
151
- memory usage: 188.8 MB
73
+ %(examples_sub)s
152
74
"""
153
75
if buf is None : # pragma: no cover
154
76
buf = sys .stdout
0 commit comments