I have a Flask app that works from a csv. I put the csv as a new table in postgres, but am having trouble changing out the data connection without breaking the app.
Currently the csv is read in under a class object. In this object, I filter the data, create a lookup table and run a machine learning algorithm (not shown for simplicity). I commented out the code where I tried to get the data from the purchases table in my_db in postgres. In the the postgres data to ultimately be a pandas dataframe.
class Recommender(object):
def __init__(self):
# df = pd.read_sql_query('select * from "purchases"',con=engine)
# self.df = df
df = pd.read_csv('data/20171027.csv', encoding='ISO-8859-1')
df.date_commande_client = pd.to_datetime(df['date_commande_client'],
format='%m/%d/%y')
df = filter_by_order_count(df) #more stuff after this
return df
I tried to read in the same data from postgres but it doesn't work. Should i not be reading it in inside the class object?
For reference I tried adding these imports and creating an engine:
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import create_engine
engine = create_engine('postgresql://user:passowrd@localhost/my_db')
app = Flask(__name__)
app.config['SECRET_KEY'] = '1234'