Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.info#

DataFrame.info(verbose=None,buf=None,max_cols=None,memory_usage=None,show_counts=None)[source]#

Print a concise summary of a DataFrame.

This method prints information about a DataFrame includingthe index dtype and columns, non-null values and memory usage.

Parameters:
verbosebool, optional

Whether to print the full summary. By default, the setting inpandas.options.display.max_info_columns is followed.

bufwritable buffer, defaults to sys.stdout

Where to send the output. By default, the output is printed tosys.stdout. Pass a writable buffer if you need to further processthe output.

max_colsint, optional

When to switch from the verbose to the truncated output. If theDataFrame has more thanmax_cols columns, the truncated outputis used. By default, the setting inpandas.options.display.max_info_columns is used.

memory_usagebool, str, optional

Specifies whether total memory usage of the DataFrameelements (including the index) should be displayed. By default,this follows thepandas.options.display.memory_usage setting.

True always show memory usage. False never shows memory usage.A value of ‘deep’ is equivalent to “True with deep introspection”.Memory usage is shown in human-readable units (base-2representation). Without deep introspection a memory estimation ismade based in column dtype and number of rows assuming valuesconsume the same memory amount for corresponding dtypes. With deepmemory introspection, a real memory usage calculation is performedat the cost of computational resources. See theFrequently Asked Questions for moredetails.

show_countsbool, optional

Whether to show the non-null counts. By default, this is shownonly if the DataFrame is smaller thanpandas.options.display.max_info_rows andpandas.options.display.max_info_columns. A value of True alwaysshows the counts, and False never shows the counts.

Returns:
None

This method prints a summary of a DataFrame and returns None.

See also

DataFrame.describe

Generate descriptive statistics of DataFrame columns.

DataFrame.memory_usage

Memory usage of DataFrame columns.

Examples

>>>int_values=[1,2,3,4,5]>>>text_values=['alpha','beta','gamma','delta','epsilon']>>>float_values=[0.0,0.25,0.5,0.75,1.0]>>>df=pd.DataFrame({"int_col":int_values,"text_col":text_values,..."float_col":float_values})>>>df    int_col text_col  float_col0        1    alpha       0.001        2     beta       0.252        3    gamma       0.503        4    delta       0.754        5  epsilon       1.00

Prints information of all columns:

>>>df.info(verbose=True)<class 'pandas.core.frame.DataFrame'>RangeIndex: 5 entries, 0 to 4Data columns (total 3 columns): #   Column     Non-Null Count  Dtype---  ------     --------------  ----- 0   int_col    5 non-null      int64 1   text_col   5 non-null      object 2   float_col  5 non-null      float64dtypes: float64(1), int64(1), object(1)memory usage: 248.0+ bytes

Prints a summary of columns count and its dtypes but not per columninformation:

>>>df.info(verbose=False)<class 'pandas.core.frame.DataFrame'>RangeIndex: 5 entries, 0 to 4Columns: 3 entries, int_col to float_coldtypes: float64(1), int64(1), object(1)memory usage: 248.0+ bytes

Pipe output of DataFrame.info to buffer instead of sys.stdout, getbuffer content and writes to a text file:

>>>importio>>>buffer=io.StringIO()>>>df.info(buf=buffer)>>>s=buffer.getvalue()>>>withopen("df_info.txt","w",...encoding="utf-8")asf:...f.write(s)260

Thememory_usage parameter allows deep introspection mode, speciallyuseful for big DataFrames and fine-tune memory optimization:

>>>random_strings_array=np.random.choice(['a','b','c'],10**6)>>>df=pd.DataFrame({...'column_1':np.random.choice(['a','b','c'],10**6),...'column_2':np.random.choice(['a','b','c'],10**6),...'column_3':np.random.choice(['a','b','c'],10**6)...})>>>df.info()<class 'pandas.core.frame.DataFrame'>RangeIndex: 1000000 entries, 0 to 999999Data columns (total 3 columns): #   Column    Non-Null Count    Dtype---  ------    --------------    ----- 0   column_1  1000000 non-null  object 1   column_2  1000000 non-null  object 2   column_3  1000000 non-null  objectdtypes: object(3)memory usage: 22.9+ MB
>>>df.info(memory_usage='deep')<class 'pandas.core.frame.DataFrame'>RangeIndex: 1000000 entries, 0 to 999999Data columns (total 3 columns): #   Column    Non-Null Count    Dtype---  ------    --------------    ----- 0   column_1  1000000 non-null  object 1   column_2  1000000 non-null  object 2   column_3  1000000 non-null  objectdtypes: object(3)memory usage: 165.9 MB

[8]ページ先頭

©2009-2025 Movatter.jp