Quantcast
Channel: Exporting Pandas Dataframe as CSV - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Exporting Pandas Dataframe as CSV

$
0
0

This is a question concerning how to allow a user to export a Pandas dataframe to CSV format in Python 3.

For context, I have a Django view that accepts POST requests from jQuery, such that when a user clicks on a button on my website, it triggers a POST request to that Django view and performs some filtering to generate a Pandas dataframe. I want the users to be able to export the dataframe on their end, not into my personal local machine/project directory.

I make a sharp distinction between "downloading" and "exporting". Downloading can be easily done through the pd.to_csv method and basically saves the CSV file into a specified directory within my local machine (or my project folder, in fact). The problem is that the behavior I want is "exporting", which I define as when a user, upon clicking a button, is able to get the dataframe on their local machine.

The way I do "exporting" currently is by converting the Dataframe to an HTML table element, returning the HTML as the response of the POST request to jQuery, and use vanilla JS to inspect the table element to export the data on the user's end, following a protocol similar to How do I export html table data as .csv file?. The problem, however, is that when the dataframe grows too big, it becomes impossible to inspect the associated table element to generate a CSV file.

Any suggestion for exporting a Pandas dataframe to CSV is appreciated - it could be an original solution, in fact.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images