Answer the question
In order to leave comments, you need to log in
How to cast a DataFrame to a dictionary/dataframe of the right kind using Pandas?
There is a select query.
print("Connecting to database...")
db = psycopg2.connect(host='localhost', user='postgres', password = 'password', database = 'DB')
print("Connected!")
print("Processing...")
prefs = pd.read_sql("select distinct ord.user_id, line.variant_id, count(line.order_id) " +
"from spree_line_items line " +
"join spree_orders ord on(line.order_id=ord.id) " +
"where ord.state='shipped' and ord.user_id is not null " +
"group by line.variant_id, ord.user_id " +
"order by ord.user_id;"
, con=db)
prefs.columns=['user', 'var', 'mark']
print("Adding marks...")
prefs.loc[prefs.mark>1, 'mark']=5
prefs.loc[prefs.mark==1, 'mark']=4
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question