【问题标题】:Can't use danfo-js library in my google script无法在我的谷歌脚本中使用 danfo-js 库
【发布时间】:2021-02-01 10:26:21
【问题描述】:

我想在 Python 中找到一些类似于 pandas 的库,并在我的 google 脚本中使用它。我找到了 danfo-js https://github.com/opensource9ja/danfojs

使用本指南https://blog.gsmart.in/es6-and-npm-modules-in-google-apps-script/ 确实将其安装在谷歌云外壳中 所以,实际上我做了什么:

  • 打开了我的谷歌云外壳
  • 已安装卡扣工具
  • 扣上登录
  • npm install danfojs-node
  • 使用以下方法创建了新的 google 脚本:clasp create --type Standalone --title "first GAS App"

所以现在,我有这个空脚本,只是想检查它是否看到了 danfo-js 库。

为了检查这一点,我用以下代码填写了它:

    function myFunction() {
      const dfd = require("danfojs-node")
      const tf = require("@tensorflow/tfjs-node")
      let data = tf.tensor2d([[20,30,40], [23,90, 28]])
      let df = new dfd.DataFrame(data)
      let tf_tensor = df.tensor
      console.log(tf_tensor);
      tf_tensor.print()
    }

运行此脚本后,我收到以下错误消息:

[20-10-18 06:17:53:783 PDT] ReferenceError: 要求未定义 在 myFunction(代码:2:15)

它链接到以下行:

    const dfd = require("danfojs-node")

看起来编译器不知道什么是“danfojs-node”,但我不明白我错过了哪些步骤。

我确实安装了 danfojs-node,在 google cloud shell 中使用以下命令:

    npm install danfojs-node

并使用我创建了这个脚本的同一个终端窗口。也许我应该在脚本中设置一些链接来连接到这个库,但我不知道我应该在哪里做。

【问题讨论】:

  • 您是否让 danfo 在 Google 应用脚本中工作?
  • 我没有继续做这个项目,抱歉

标签: google-apps-script google-cloud-shell danfojs


【解决方案1】:

Apps 脚本不是 Node.js

您无法像创建 node.js 应用程序时那样安装外部模块和库。在 Apps 脚本中使用外部库的支持方式是通过项目的资源安装它们。

所以本质上,这可以通过转到项目的 Resources > Libraries... 来完成。

您必须检查您计划使用的库是否受 Apps 脚本支持,如果支持,请使用上述步骤包含它。

参考

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多