Skip to content

ENH: Include df.attrs metadata in to_csv output #53816

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

Conversation

canthonyscott
Copy link

@canthonyscott canthonyscott commented Jun 23, 2023

This new functionality writes DataFrame metadata stored in df.attrs as header/comment lines at the top of a CSV file.

The to_csv() method had a comment param added to its call, matching the read_csv() method signature
If this param is set all key/values will be written to the beginning of the CSV file in the following format [comment][key]:[value]

There was previous PR for this (#53740) that I closed. I accidentally butchered that previous branch, this is the new PR with a clean, fresh branch

@canthonyscott canthonyscott changed the title Df attrs csv comments ENH: Include df.attrs metadata in to_csv output Jun 23, 2023
@mroeschke mroeschke added the IO CSV read_csv, to_csv label Jun 23, 2023
@@ -3636,6 +3636,7 @@ def to_csv(
decimal: str = ...,
errors: OpenFileErrors = ...,
storage_options: StorageOptions = ...,
comment: str | None = ...,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this string and not bool?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intended to mirror the read_csv parameter for consistency between the two. Setting it will write the comments with that prefix.

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Aug 14, 2023
@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO CSV read_csv, to_csv Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Include df.attrs in to_csv output
3 participants