我正在尝试使用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 |
+------------+-------+-----------+