首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TabPy Python脚本“未终止日期”

TabPy Python脚本“未终止日期”
EN

Stack Overflow用户
提问于 2019-03-05 05:38:31
回答 1查看 169关注 0票数 2

我正在尝试使用Tableau计算字段来使用我的python脚本。我的python脚本查询数据库。我目前在Spyder中使用它。

目前,我收到了Unterminated Date错误。

下面的线条用红色下划线,

代码语言:javascript
复制
#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脚本:

代码语言:javascript
复制
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中显示的预期结果:

代码语言:javascript
复制
+------------+-------+-----------+
|   Date     | Node  |    sum    |
+------------+-------+-----------+
| 04/02/2019 | Stack | -2.90E+06 |
| 05/02/2019 | Stack | -2.90E+06 |
+------------+-------+-----------+
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-06 03:03:36

您看到的错误是由Tableau计算字段中的python comment #符号引起的。

Tableau将#符号视为显式声明日期的方法。下面是一个会导致您看到的“Unterminated date”错误的示例(请注意日期后缺少的#符号):

如果删除Tableau计算字段中的注释,它将正确编译。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54991932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档