簡體   English   中英

TabPy Python 腳本“未終止日期”

[英]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 |
+------------+-------+-----------+

您看到的錯誤是由 Tableau 計算字段中的 python 注釋 # 符號引起的。

Tableau 將 # 符號視為顯式聲明日期的方法。 這是一個會導致您看到的“未終止日期”錯誤的示例(請注意日期后缺少的 # 符號):

在此處輸入圖片說明

如果您刪除 Tableau 計算字段中的注釋,它應該可以正確編譯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM