Building off of the previous answer. The solution below will place the string collected from the buffer directly into a pandas DataFrame without having to save a temp file to disk

import io
buf = io.StringIO()
df.info(buf=buf)
s = buf.getvalue()
lines = [line.split() for line in s.splitlines()[3:-2]]
pd.DataFrame(lines)

Explaination:

  • s.splitlines() - creates a list from the string where a new line character is found
  • indexing [3:-2] - removes the first three lines and last two so that it will fit nicely into columns for the data frame
Answer from Bryce Ramgovind on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.info.html
pandas.DataFrame.info — pandas 3.0.2 documentation
The memory_usage parameter allows deep introspection mode, specially useful 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.DataFrame'> RangeIndex: 1000000 entries, 0 to 999999 Data columns (total 3 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 column_1 1000000 non-null str 1 column_2 1000000 non-null str 2 column_3 1000000 non-null str dtypes: str(3) memory usage: 25.7 MB ·
🌐
W3Schools
w3schools.com › python › pandas › ref_df_info.asp
Pandas DataFrame info() Method
Pandas HOME Pandas Intro Pandas ... Wrong Format Cleaning Wrong Data Removing Duplicates ... The info() method prints information about the DataFrame....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pandas-dataframe-info
Python | Pandas dataframe.info() - GeeksforGeeks
July 26, 2025 - Python · import pandas as pd df = pd.read_csv("/content/nba.csv") df.info() Output : Here info() provides an overview of the DataFrame's structure such as number of entries, column names, data types and non-null counts.
🌐
Llego
llego.dev › home › blog › a comprehensive guide to pandas df.info() in python
A Comprehensive Guide to Pandas df.info() in Python - llego.dev
March 24, 2023 - We will cover the following topics in-depth with example code snippets: ... The df.info() method in Pandas provides an overview of the DataFrame by outputting information about the index, columns, data types, memory usage and more.
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › info
Python Pandas DataFrame info() - Display Information | Vultr Docs
November 25, 2024 - Import the pandas library and create a DataFrame. Call the info() method to view the summary of the DataFrame. ... import pandas as pd data = {'Name': ['John', 'Anna', 'Peter', 'Linda'], 'Age': [28, 22, 34, 42], 'City': ['New York', 'Paris', ...
Top answer
1 of 4
4

Building off of the previous answer. The solution below will place the string collected from the buffer directly into a pandas DataFrame without having to save a temp file to disk

import io
buf = io.StringIO()
df.info(buf=buf)
s = buf.getvalue()
lines = [line.split() for line in s.splitlines()[3:-2]]
pd.DataFrame(lines)

Explaination:

  • s.splitlines() - creates a list from the string where a new line character is found
  • indexing [3:-2] - removes the first three lines and last two so that it will fit nicely into columns for the data frame
2 of 4
2

While the info() method directly prints the information to the output, and even when you use the buffer to extract the info, it extracts it in the form of text lines, which are hardly useful for further processing.

The above mentioned solution does work, but it creates a problem when your column names have spaces or are inconsistently named for you to be able to use the line.split() with some other separator character.

I couldn't search of any way to do this using the default info() method. So, I made my own function to do this. And it is not that complicated.

def infoOut(data,details=False):
    dfInfo = data.columns.to_frame(name='Column')
    dfInfo['Non-Null Count'] = data.notna().sum()
    dfInfo['Dtype'] = data.dtypes
    dfInfo.reset_index(drop=True,inplace=True)
    if details:
        rangeIndex = (dfInfo['Non-Null Count'].min(),dfInfo['Non-Null Count'].min())
        totalColumns = dfInfo['Column'].count()
        dtypesCount = dfInfo['Dtype'].value_counts()
        totalMemory = dfInfo.memory_usage().sum()
        return dfInfo, rangeIndex, totalColumns, dtypesCount, totalMemory
    else:
        return dfInfo

Usage:

variable = infoOut(yourDataFrameObject)
#or
var1, var2, var3, var4, var5 = infoOut(yourDataFrameObject,details=True)

This function will return the exact table structure as returned by the info method for your supplied dataframe, and that too in a dataframe format. Further, if you supply with an argument details=True, then it will also give our other information that info() gives out like memory, summary counts, etc.

Modify the function as you like.

Good day.

🌐
Programiz
programiz.com › python-programming › pandas › methods › info
Pandas info()
Check leap year All Python Examples · The info() method in Pandas provides a concise summary of a DataFrame. This summary includes information about the index data type and column data types, non-null values, and memory usage. import pandas as pd # sample DataFrame data = {'A': [1, 2, None], ...
🌐
Stack Overflow
stackoverflow.com › questions › 40379104 › python-pandas-df-info
Python Pandas df.info - Stack Overflow
Explore Stack Internal ... Total files to Process : 100 <class 'pandas.core.frame.DataFrame'> RangeIndex: 1713078 entries, 0 to 1713077 Columns: 322 entries, #RIC to Reuters Classification Scheme.1 dtypes: object(322) memory usage: 17.1 GB None · I created a dataframe from 100 csv files and above you have df.info(memory_usage='deep') for that.
Find elsewhere
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.DataFrame.info.html
pyspark.pandas.DataFrame.info — PySpark 4.1.1 documentation
>>> 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 = ps.DataFrame( ... {"int_col": int_values, "text_col": text_values, "float_col": float_values}, ... columns=['int_col', 'text_col', 'float_col']) >>> df int_col text_col float_col 0 1 alpha 0.00 1 2 beta 0.25 2 3 gamma 0.50 3 4 delta 0.75 4 5 epsilon 1.00 · Prints information of all columns: >>> df.info(verbose=True) <class 'pyspark.pandas.frame.DataFrame'> Index: 5 entries, 0 to 4 Data columns (total 3 columns): # Column Non-Null Count Dtype
🌐
Stack Overflow
stackoverflow.com › questions › 65896566 › pandas-dataframe-info-method
Pandas DataFrame "info" method - Stack Overflow
python-3.8 · Share · Improve this question · Follow · asked Jan 26, 2021 at 6:00 · Ong K.S · 32322 gold badges77 silver badges2222 bronze badges 2 · 1 · Maybe duplicates in index, how working rempove them by df = df.reset_index(drop=True) and then print (df.info()) ?
🌐
Educative
educative.io › answers › what-is-info-function-in-pandas
What is info function in Pandas?
The info function in Pandas is displays a summary of the dataframe. It displays column names, data types, the number of non-null values, and memory usage · The syntax of the info function is as follows:
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
What information is returned from df.info()? - Python FAQ - Codecademy Forums
August 11, 2018 - Question What information is returned when we run df.info()? Answer When using .info() in Pandas, it will return information about the dataframe including the data types of each column and memory usage of the entire data.
🌐
Data Science Dojo
discuss.datasciencedojo.com › python
How to get information about a Pandas Dataframe in Python? - Python - Data Science Dojo Discussions
March 24, 2023 - I’m working with a large Pandas dataframe and I need to quickly get an overview of its contents, such as the number of rows and columns, and the data types of each column. I’m not sure if there are functions or methods a…
🌐
LabEx
labex.io › tutorials › pandas-dataframe-info-method-68636
Pandas DataFrame Info Method | LabEx
The info() method in the Python Pandas library is a useful method to get a quick summary of a DataFrame. It provides information about the index dtype and columns, non-null values, and memory usage.
🌐
Snowflake Documentation
docs.snowflake.com › en › developer-guide › snowpark › reference › python › 1.19.0 › modin › pandas_api › snowflake.snowpark.modin.pandas.DataFrame.info
modin.pandas.DataFrame.info | Snowflake Documentation
By default, this is shown only if the DataFrame is smaller than pandas.options.display.max_info_rows and pandas.options.display.max_info_columns. A value of True always shows the counts, and False never shows the counts. ... This method prints a summary of a DataFrame and returns None.
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.DataFrame.info.html
pandas.DataFrame.info — pandas documentation
The memory_usage parameter allows deep introspection mode, specially useful 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.DataFrame'> RangeIndex: 1000000 entries, 0 to 999999 Data columns (total 3 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 column_1 1000000 non-null str 1 column_2 1000000 non-null str 2 column_3 1000000 non-null str dtypes: str(3) memory usage: 25.7 MB ·
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas dataframe info() function
Pandas DataFrame info() Function - Spark By {Examples}
July 29, 2024 - Alternatively, to demonstrate the basic usage of the info() function with the DataFrame you’ve created, you can call the info() method on the DataFrame. This will provide a concise summary of the DataFrame, including the number of entries, the column names, non-null counts, and data types. # Basic usage of info() function print("DataFrame Info:\n") df.info()
🌐
w3resource
w3resource.com › pandas › dataframe › dataframe-info.php
Pandas DataFrame: - info() function - w3resource
August 19, 2022 - The info() function is used to print a concise summary of a DataFrame. This method prints information about a DataFrame including the index dtype and column dtypes, non-null values and memory usage.