Python ??? ???? mysql? ????? ???. "?? ?? ??? ??????. Python '?????'? MySQL ???? ??? ? ????."?? ??? ?????. ?? ???? ? ??????.
import pandas as pd from datetime import date import mysql.connector from mysql.connector import Error def priceStock(tickers): today = pd.to_datetime("today").strftime("%Y-%m-%d") for ticker in tickers: conn = mysql.connector.connect(host='103.200.22.212', database='analysis_stock', user='analysis_PhamThiLinhChi', password='Phamthilinhchi') new_record = stock_historical_data(ticker, '2018-01-01', today) new_record.insert(0, 'ticker', ticker) table = 'priceStock' cursor = conn.cursor() #loop through the data frame for i,row in new_record.iterrows(): #here %s means string values sql = "INSERT INTO " + table + " VALUES (%s,%s,%s,%s,%s,%s,%s)" #?oán ch?c là do format time t? python sang sql ko kh?p cursor.execute(sql, tuple(row)) print("Record inserted") # the connection is not auto committed by default, so we must commit to save our changes conn.commit() priceStock(['VIC'])
to_sql? ??? ? ????. to_sql? SQLAlchemy? ???? SQLAlchemy? MySQL? ????? ?? ??? ???? ???
???????? ?? ??? ?? ??? ?????.
???