Answer the question
In order to leave comments, you need to log in
Python how to save in excel?
Friends help
, there is a function for saving from sql to excel
and I can’t figure out how to save not the last result, but the entire search result,
I even understand that in theory I need to save it as a sheet, but I can’t figure out how to break it down by values
def finde_sql(find):
cursor, connect = sql_tab()
find_a = '%' + '%%'.join(find.split()) + '%'
for values in cursor.execute(f"SELECT id,brand,model,description,prise,old_prise,date FROM svz_parsing WHERE model LIKE '{find_a}' "):
id, brand, model, description, prise, old_prise, date = values
data_svz = pd.DataFrame({'Бренд':[brand],'Модель':[model],'Описание':[description],'цена':[prise],'старя цена':[old_prise],'дата обновления':[date]})
data_svz.to_excel(direct+'/data_pars.xlsx', sheet_name='Связной', index=False)
Answer the question
In order to leave comments, you need to log in
here at each iteration you overwrite DF
data_svz = pd.DataFrame({'Бренд':[brand],'Модель':[model],'Описание':[description],'цена':[prise],'старя цена':[old_prise],'дата обновления':[date]})
id, brand, model, description, prise, old_prise, date = values
data = {'Бренд':[brand],'Модель':[model],'Описание':[description],'цена':[prise],'старя цена':[old_prise],'дата обновления':[date]}
data_svz = data_svz.append(data , ignore_index=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question