[英]TabPy Python Script "Unterminated Date"
我正在嘗試使用 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
全屏:
我想在畫面中顯示的預期結果:
+------------+-------+-----------+
| Date | Node | sum |
+------------+-------+-----------+
| 04/02/2019 | Stack | -2.90E+06 |
| 05/02/2019 | Stack | -2.90E+06 |
+------------+-------+-----------+
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.