civisanalytics / civis-python

Civis API Python Client
BSD 3-Clause "New" or "Revised" License
34 stars 26 forks source link

Convenience function for persisting dataframe to files endpoint #262

Closed elsander closed 5 years ago

elsander commented 6 years ago

civis.io has a function file_to_dataframe, but no function going in the opposite direction. I find myself rewriting this simple function for myself a lot, and I thought it would make a nice little convenience for others. @keithing, would you be interested in including something like this in the civis.io function suite (I would make a PR)?

elsander commented 6 years ago

(this is essentially a thin wrapper around civis.io.dataframe_to_file, but I find it quite useful and I'm guessing other users would as well)

keithing commented 6 years ago

If I understand correctly, this is just a two liner:

df.to_csv(filename)
file_to_civis(filename)

But if you see the need for the function I'd be happy to review.

elsander commented 6 years ago

The most basic version of it is that two-liner, but it's nicer to wrap it in a temporary directory so that you don't end up with a bunch of local junk files. It's still only a few lines, but it's still convenient to have. It's also just nice to have the reverse functionality, since most of civis.io has functions for both i/o directions, and it's surprising as a user when that's not the case for files <-> pandas.