【问题标题】:extract data between dates from MYSQL into pandas从 MYSQL 中提取日期之间的数据到 pandas
【发布时间】:2020-04-09 06:57:43
【问题描述】:
**当我在查询下方运行时** 从 sqlalchemy 导入 create_engine 导入 pymysql 将熊猫导入为 pd 导入日期时间 db_connection_str = 'mysql+pymysql://root:*****@localhost/northwind' db_connection = create_engine(db_connection_str) df = pd.read_sql('SELECT * FROM employees where BirthDate between '1948-12-08' and '1960-05-29'', con=db_connection) df **我收到以下错误** 文件“”,第 7 行 df = pd.read_sql('SELECT * FROM employees where BirthDate between '1948-12-8' and '1960-5-29'', con=db_connection) ^ SyntaxError:无效的语法 -------------------------------------------------- ------------------------------------------------

【问题讨论】:

    标签: python mysql pandas date


    【解决方案1】:

    使用双引号将 sql 语句括起来,因为您在语句中使用单引号表示日期:

    df = pd.read_sql("SELECT * FROM employees where BirthDate between '1948-12-08' and '1960-05-29'", con=db_connection)
    

    【讨论】:

      猜你喜欢
      • 2017-11-16
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-01
      • 2016-07-20
      相关资源
      最近更新 更多