Block 65: Flask: Serving Data from pandas
Connect Flask to a pandas dataset and serve computed results.
Concepts
- Loading a CSV once at startup with global variable
- Passing DataFrame data to templates
- Returning filtered data as JSON from API endpoint
- Basic query string parameters: request.args
Code Examples
See exercise below.
Exercise
Build a Flask app that loads the Iris dataset and serves: /data (JSON all), /stats (JSON describe), /species/<name> (filtered rows). Render a simple HTML table of the first 10 rows via a template.
Homework
What is the risk of using a global DataFrame in Flask? How could you improve this?