4 ms·
Funny that the example you give is one of the (many) frustrations with Pandas. It’s ‘read_<format>’ to read something in, but ‘to_<format>’ to write it out? In
by mft_ 6y ago
Funny that the example you give is one of the (many) frustrations with Pandas.
It’s ‘read_<format>’ to read something in, but ‘to_<format>’ to write it out? In which world is this intuitive? Surely it should be read/write or even from/to?
- efxhoy 6y agoIt's `pandas.read_<format> -> DataFrame` and `DataFrame.to_<format>`. So pandas reads a data format and gives you a dataframe. The `to_<format>` are instane methods of the DataFrame where you write a dataframe to a format. To me that makes sense.
- mft_ 6y agoSure, you can create a sort-of logic to fit the existing naming, but it's still something you have to learn. Imagine you were using Pandas for the first time, working through a tutorial, and you've just learned that pd.read_csv reads a csv into a dataframe. Intuitively, what would you expect the corresponding output function to be called? I'd hazard that a vast majority of people would guess at some version of write_csv, and would experiment with either pd.write_csv, or df.write_csv.