Skip to content

ENH: df.to_csv() and pd.read_csv() defaults do not give back original data #41311

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
edmundsj opened this issue May 4, 2021 · 3 comments
Closed
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@edmundsj
Copy link

edmundsj commented May 4, 2021

Is your feature request related to a problem?

I expect when loading and saving CSV data that whatever defaults used for loading and saving can be used mindlessly if my data is simple enough. For example, in the below example, I would expect that new_df is equal to df:

df = pd.DataFrame({'time (ms)': [1, 2, 3, 4]})
df.to_csv('test.csv')
new_df = pd.read_csv('test.csv')

However, this is not so. The index is saved as the first column by default, but is not read as the first column by default when loading data with read_csv().

Describe the solution you'd like

I should not have to pass in additional arguments to get the simplest use case to work for loading and saving data. I suggest either not saving the index by default when converting to CSV (this seems less desirable), or setting the index_col=0 by default when loading a CSV file.

API breaking implications

index_col would be set by default

Describe alternatives you've considered

Manually avoiding saving the index, and manually adding the index_col=0 keyword argument when loading CSV data. Both have caused me endless frustration.

@edmundsj edmundsj added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels May 4, 2021
@jreback
Copy link
Contributor

jreback commented May 4, 2021

search for from_cav in the issue tracker

this was changed a long time ago and lots of discussion on why this is

@jreback jreback added this to the No action milestone May 4, 2021
@jreback jreback closed this as completed May 4, 2021
@edmundsj
Copy link
Author

edmundsj commented May 4, 2021

from_cav yields only this result. Can you link to the specific discussion?

@jreback
Copy link
Contributor

jreback commented May 4, 2021

#4595

https://github.com/pandas-dev/pandas/issues?q=from_csv yields 49 results so other commentary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants