|
206 | 206 | format as fmt, |
207 | 207 | ) |
208 | 208 | from pandas.io.formats.info import ( |
209 | | - BaseInfo, |
210 | 209 | DataFrameInfo, |
| 210 | + frame_sub_kwargs, |
211 | 211 | ) |
212 | 212 | import pandas.plotting |
213 | 213 |
|
@@ -3138,122 +3138,7 @@ def to_xml( |
3138 | 3138 | return xml_formatter.write_output() |
3139 | 3139 |
|
3140 | 3140 | # ---------------------------------------------------------------------- |
3141 | | - @Substitution( |
3142 | | - klass="DataFrame", |
3143 | | - type_sub=" and columns", |
3144 | | - max_cols_sub=dedent( |
3145 | | - """\ |
3146 | | - max_cols : int, optional |
3147 | | - When to switch from the verbose to the truncated output. If the |
3148 | | - DataFrame has more than `max_cols` columns, the truncated output |
3149 | | - is used. By default, the setting in |
3150 | | - ``pandas.options.display.max_info_columns`` is used.""" |
3151 | | - ), |
3152 | | - show_counts_sub=dedent( |
3153 | | - """\ |
3154 | | - show_counts : bool, optional |
3155 | | - Whether to show the non-null counts. By default, this is shown |
3156 | | - only if the DataFrame is smaller than |
3157 | | - ``pandas.options.display.max_info_rows`` and |
3158 | | - ``pandas.options.display.max_info_columns``. A value of True always |
3159 | | - shows the counts, and False never shows the counts. |
3160 | | - null_counts : bool, optional |
3161 | | - .. deprecated:: 1.2.0 |
3162 | | - Use show_counts instead.""" |
3163 | | - ), |
3164 | | - examples_sub=dedent( |
3165 | | - """\ |
3166 | | - >>> int_values = [1, 2, 3, 4, 5] |
3167 | | - >>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon'] |
3168 | | - >>> float_values = [0.0, 0.25, 0.5, 0.75, 1.0] |
3169 | | - >>> df = pd.DataFrame({"int_col": int_values, "text_col": text_values, |
3170 | | - ... "float_col": float_values}) |
3171 | | - >>> df |
3172 | | - int_col text_col float_col |
3173 | | - 0 1 alpha 0.00 |
3174 | | - 1 2 beta 0.25 |
3175 | | - 2 3 gamma 0.50 |
3176 | | - 3 4 delta 0.75 |
3177 | | - 4 5 epsilon 1.00 |
3178 | | -
|
3179 | | - Prints information of all columns: |
3180 | | -
|
3181 | | - >>> df.info(verbose=True) |
3182 | | - <class 'pandas.core.frame.DataFrame'> |
3183 | | - RangeIndex: 5 entries, 0 to 4 |
3184 | | - Data columns (total 3 columns): |
3185 | | - # Column Non-Null Count Dtype |
3186 | | - --- ------ -------------- ----- |
3187 | | - 0 int_col 5 non-null int64 |
3188 | | - 1 text_col 5 non-null object |
3189 | | - 2 float_col 5 non-null float64 |
3190 | | - dtypes: float64(1), int64(1), object(1) |
3191 | | - memory usage: 248.0+ bytes |
3192 | | -
|
3193 | | - Prints a summary of columns count and its dtypes but not per column |
3194 | | - information: |
3195 | | -
|
3196 | | - >>> df.info(verbose=False) |
3197 | | - <class 'pandas.core.frame.DataFrame'> |
3198 | | - RangeIndex: 5 entries, 0 to 4 |
3199 | | - Columns: 3 entries, int_col to float_col |
3200 | | - dtypes: float64(1), int64(1), object(1) |
3201 | | - memory usage: 248.0+ bytes |
3202 | | -
|
3203 | | - Pipe output of DataFrame.info to buffer instead of sys.stdout, get |
3204 | | - buffer content and writes to a text file: |
3205 | | -
|
3206 | | - >>> import io |
3207 | | - >>> buffer = io.StringIO() |
3208 | | - >>> df.info(buf=buffer) |
3209 | | - >>> s = buffer.getvalue() |
3210 | | - >>> with open("df_info.txt", "w", |
3211 | | - ... encoding="utf-8") as f: # doctest: +SKIP |
3212 | | - ... f.write(s) |
3213 | | - 260 |
3214 | | -
|
3215 | | - The `memory_usage` parameter allows deep introspection mode, specially |
3216 | | - useful for big DataFrames and fine-tune memory optimization: |
3217 | | -
|
3218 | | - >>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6) |
3219 | | - >>> df = pd.DataFrame({ |
3220 | | - ... 'column_1': np.random.choice(['a', 'b', 'c'], 10 ** 6), |
3221 | | - ... 'column_2': np.random.choice(['a', 'b', 'c'], 10 ** 6), |
3222 | | - ... 'column_3': np.random.choice(['a', 'b', 'c'], 10 ** 6) |
3223 | | - ... }) |
3224 | | - >>> df.info() |
3225 | | - <class 'pandas.core.frame.DataFrame'> |
3226 | | - RangeIndex: 1000000 entries, 0 to 999999 |
3227 | | - Data columns (total 3 columns): |
3228 | | - # Column Non-Null Count Dtype |
3229 | | - --- ------ -------------- ----- |
3230 | | - 0 column_1 1000000 non-null object |
3231 | | - 1 column_2 1000000 non-null object |
3232 | | - 2 column_3 1000000 non-null object |
3233 | | - dtypes: object(3) |
3234 | | - memory usage: 22.9+ MB |
3235 | | -
|
3236 | | - >>> df.info(memory_usage='deep') |
3237 | | - <class 'pandas.core.frame.DataFrame'> |
3238 | | - RangeIndex: 1000000 entries, 0 to 999999 |
3239 | | - Data columns (total 3 columns): |
3240 | | - # Column Non-Null Count Dtype |
3241 | | - --- ------ -------------- ----- |
3242 | | - 0 column_1 1000000 non-null object |
3243 | | - 1 column_2 1000000 non-null object |
3244 | | - 2 column_3 1000000 non-null object |
3245 | | - dtypes: object(3) |
3246 | | - memory usage: 165.9 MB""" |
3247 | | - ), |
3248 | | - see_also_sub=dedent( |
3249 | | - """\ |
3250 | | - DataFrame.describe: Generate descriptive statistics of DataFrame |
3251 | | - columns. |
3252 | | - DataFrame.memory_usage: Memory usage of DataFrame columns.""" |
3253 | | - ), |
3254 | | - version_added_sub="", |
3255 | | - ) |
3256 | | - @doc(BaseInfo.render) |
| 3141 | + @doc(DataFrameInfo.render, **frame_sub_kwargs) |
3257 | 3142 | def info( |
3258 | 3143 | self, |
3259 | 3144 | verbose: bool | None = None, |
|
0 commit comments