我正在尝试使用Tableau计算字段来使用我的python脚本。我的python脚本查询数据库。我目前在Spyder中使用它。
目前,我收到了Unterminated Date错误。
下面的线条用红色下划线,
#Remove the list comma
bookList = bookList[:-1]
sql = sql.format ("'" + startDate + "'", "'" + endDate +"'", "'" + nodeNames +"'")
print (sql)
df_Cs01 = pd.read_sql(sql,con)
con.close()
return df_Cs01
)错误消息:

我的python脚本:
import pandas as pd
import pyodbc, os
import datetime
def GetData (startDate, endDate, nodeNames, server='server'):
con = pyodbc.connect(r'DSN='+server,autocommit=True)
#query removed for simplicity.
sql = """ e (R.asOfDate >= {0} and R.asOfDate <= {1})
and R.node = {2} """
bookList = ""
print (nodeNames)
#loop through the nodeNames
for nodeName in nodeNames:
bookList = bookList + "'" + nodeName + "',"
#Remove the list comma
bookList = bookList[:-1]
sql = sql.format ("'" + startDate + "'", "'" + endDate +"'", "'" + nodeNames +"'")
print (sql)
df_Cs01 = pd.read_sql(sql,con)
con.close()
return df_Cs01全屏:

我希望在tableau中显示的预期结果:
+------------+-------+-----------+
| Date | Node | sum |
+------------+-------+-----------+
| 04/02/2019 | Stack | -2.90E+06 |
| 05/02/2019 | Stack | -2.90E+06 |
+------------+-------+-----------+发布于 2019-03-06 03:03:36
您看到的错误是由Tableau计算字段中的python comment #符号引起的。
Tableau将#符号视为显式声明日期的方法。下面是一个会导致您看到的“Unterminated date”错误的示例(请注意日期后缺少的#符号):

如果删除Tableau计算字段中的注释,它将正确编译。
https://stackoverflow.com/questions/54991932
复制相似问题