Skip to content

ENH: DataFrame.info() returns a DataFrame rather than printing a table #59387

@jpeacock29

Description

@jpeacock29

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I wish I could use Pandas to get the information provided by DataFrame.info() in a more usable format. For example, this function currently prints a table describing each column in the DataFrame, info on Index, memory usage, etc. However, since this information is returned as string, it is difficult to use downstream. Perhaps we could add a flag like return_info set to False by default, but when True would return a dictionary containing the above information.

Feature Description

class DataFrame:
...
def info(return_info=False, [other existing params]):
  # existing implementation that calculates the below values
  if return_info:
    return {
      'Column summary': pd.DataFrame({'#': [0, 1, 2], 'Column': [nameCol1, nameCol2, nameCol3], 'Non-Null count': [4,2,5],...}),
      'Memory usage': 248
      'Index type': 'RangeIndex',
      'Index entries': 5,
      ...}  

Alternative Solutions

I suppose you could either gather all the information manually by calling other functions and then make the JSON yourself. Or you could parse the string output of .info().

Additional Context

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions