-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC update DataFrame.to_csv write modes (#51839) #51881
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
DOC update DataFrame.to_csv write modes (#51839) #51881
Conversation
Modify write mode descriptions and add an explanation for b and t mode.
pandas/core/generic.py
Outdated
- 'a', open for writing, appending to the end of file if it exists. | ||
|
||
Including 'b' or 't' in the mode parameter will inform Pandas whether | ||
'path_or_buf' requires string or binary data. However, in most cases, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think path_or_buf
needs backticks. I'm not sure whether the quoted strings should also be wrapped in backticks.
Put path_or_buf in backticks.
…zaSK/pandas into DataFrame_to_csv_Doc_Fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job. Just one minor comment.
pandas/core/generic.py
Outdated
- 'x', open for exclusive creation, failing if the file already exists. | ||
- 'a', open for writing, appending to the end of file if it exists. | ||
|
||
Including 'b' or 't' in the mode parameter will inform Pandas whether |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually use pandas lowercase.
pandas/core/generic.py
Outdated
`path_or_buf` requires string or binary data. However, in most cases, | ||
this should not be necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point, but I don't think it makes sense to have binary csv files. I think this was a comment in the issue, about using b
, which in general makes sense, but I don't see how for to_csv
it could make sense to save data in a binary file. Unless I'm missing something (correct me if I'm wong), better to simply delete this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your input.
I also think the same, but we had a discussion with @twoertwein earlier here #51881 (comment).
Could you please share your thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that part is more confusing than helpful, feel free to remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying. I agree with these comments in general, bit I don't think in this particular case it's possible to binary data. Csv relies on the delimiter, the quote character and the line break to understand the structure. Binary data could have any of those and break a csv. Unless I'm missing something, it's not that in most cases "b" shouldn't be used, it can never be used. To me it makes more sense to remove that comment, since I think it's giving the impression that users can actually use binary csv's in some cases, and some may start researching about it. So, probably a bit confusing and distracting.
Feel free to disagree, but that's how I feel about that comment.
Remove the 'b' and 't' modes from the description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks @HamidrezaSK
I'm not sure if we could remove the open for ...
parts, and be more concise, something like 'w', truncate the file before writing
, fail if the file already exists
, append to the end of the file if it exists
. Not sure if the beginning adds more noise than value. But either way, great addition, thanks!
Modify 'w', 'a', and 'x' write mode's description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I think this explanation is a lot clearer.
Thanks @HamidrezaSK |
Uh oh!
There was an error while loading. Please reload this page.