Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 3 tasks
jpeacock29 opened this issue Aug 2, 2024 · 3 comments
Closed
1 of 3 tasks
Assignees
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement

Comments

@jpeacock29
Copy link
Contributor

jpeacock29 commented Aug 2, 2024

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

@jpeacock29 jpeacock29 added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 2, 2024
@rhshadrach
Copy link
Member

Thanks for the feature request. It seems readily achievable to create the this in a simple function. Even better, that would give you full control over what is collected (so you could collect more or less depending on your use case). An alternative would be to vendor the code here:

class DataFrameInfo(_BaseInfo):

@rhshadrach rhshadrach added Closing Candidate May be closeable, needs more eyeballs and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 3, 2024
@GuglielmoCerri
Copy link

take

@mroeschke
Copy link
Member

Agreed that this feature is probably not worth including in pandas. Thanks for the suggestion but closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants