我要跑了pd.read_sql语句没有日期解析。在
在pd.read_sql
文档中的parse_dates
参数下,它声明它可以是Dict of {column_name: arg dict}, where the arg dict corresponds to the keyword arguments of pandas.to_datetime() Especially useful with databases without native Datetime support, such as SQLite.
在to_datetime
文档中,默认情况下,errors='raise'
。如果我可以将其更改为errors='ignore'
或{
我试着这样实施,见下文:
pd.read_sql(query, con, parse_dates={'col_name': {'errors': 'ignore'}}, chunksize=10**5)
它运行时没有错误,但仍然解析日期。在
代码与此问题不太相关。基本上就是:
df = pandas.read_sql(sql, con, index_col=None, coerce_float=True, params=None, parse_dates=None, columns=None, chunksize=10**5)
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_sql.html
需要关闭日期分析以防止此错误:
File "expense.py", line 20, in <module>
for df in gen:
File "C:\Users\rfrigo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\io\sql.py", line 1453, in _query_iterator
data = cursor.fetchmany(chunksize)
ValueError: year -6371 is out of range
您的问题是,当您指定chunksize时,请看以下示例:
当我不指定chunksize=10**5时,df只是空的,但是当我指定chunksize时,它导致
^{pr2}$可能先尝试运行较小的查询,例如使用limit 1,然后使用chunksize成功运行查询
相关问题 更多 >
编程相关推荐