12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import pandas as pd
- from sqlalchemy import create_engine
- from base_class import BaseVariableFunction
- from base_class import *
- baseclass = BaseVariableFunction(__file__)
- username = 'root'
- password = '123456'
- host = 'localhost'
- database = 'mine_01'
- table_name = 'table_01'
- engine = create_engine(f'mysql+pymysql://{username}:{password}@{host}/{database}')
- print("engine=",engine)
- con = engine.connect()
- print(con)
-
- df = pd.read_excel(baseclass.library_path/f"a_case.xlsx",dtype =object)
- df = df.astype({
- "time":int,
- })
-
- print(df.head(5))
- try:
- df.to_sql(name=table_name, con=con, if_exists='replace', index=False)
- print(f"DataFrame successfully written to table {table_name}")
- except Exception as e:
- print(f"An error occurred: {e}")
-
|