I am trying to read a database stored in MySQL to python.
I understand how to connect and read the whole data, but I am having problem in how to just get the data from a specific date. Like how to do SELECT * FROM country WHERE TIMESTAMP(date)= '2022-02-19' for example
I can get the whole table doing the following
engine = create_engine(mysql connection here)
tables = ['country','state','county']
df = pd.read_sql('SELECT * FROM ' tables[0], con=engine)
or
df = pd.read_sql_table(tables[0], engine)
But now how I filter using a date? Let's say just bring everything from 2022-02-19
CodePudding user response:
df = pd.read_sql(f"SELECT * FROM {tables[0]} WHERE date = '2022-02-19'", con=engine)