quick note (Cx_Oracle is problematic on my laptop)
the code I have is as below which works fine in terms of pulling data in:
import pandas as pdimport mysql.connectorfrom mysql.connector import Errorimport numpy as npimport os, oracledb, csvfrom sqlalchemy.exc import SQLAlchemyErrorimport sqlalchemy as safrom sqlalchemy.engine import URLfrom sqlalchemy import create_engineimport cx_Oracleimport pyodbcfrom pandas import DataFramepd.set_option('display.max_columns', 8)pd.set_option('display.width', 500)dfO = pd.read_csv(r'C:\Offers_csv.csv')SchList = dfO['Unit'].dropna().unique().tolist()SchList=[ '%.0f' % elem for elem in SchList ]print(SchList)my_string = ",".join(str(element) for element in SchList)print(my_string)# Convert SchList to a comma-separated stringSchList_str = ','.join(map(str, SchList))# Construct the SQL query with the list of X valuessql_query = f"SELECT HOUR,Unit,max(Y),M,N,NL,CS,IS,HSC,VTT,VFT FROM OfferHourly WHERE HOUR > TO_DATE('2022-09-01', 'YYYY-MM-DD') AND XIN ({SchList_str}) group by HOUR,Unit,M,N,NL,CS,IS,HSC,VTT,VFT"# Execute the SQL query and fetch the resultscursor = connection.cursor()cursor.execute(sql_query)res = cursor.fetchall()# Convert the fetched data into a pandas DataFramedf_res = pd.DataFrame(res, columns=[desc[0] for desc in cursor.description])# Close the cursorcursor.close()# Print the DataFrameprint(df_res.head())
I just need the part where I can insert this new table back into the OffersHourly in Oracle to update it with the new values.
Thank you!