如何使用Python将数据从Gsheet复制到YAML?

发布于 2025-02-03 07:47:34 字数 1217 浏览 3 评论 0原文

你能帮忙吗?我有一项任务将指标从Google Sheep复制到YAML文件(一行=一个Metric =可以是一个单独的YAML文件)。 我发现我可以使用gspread读取Gsheet和pyyaml yaml.dump的数据来创建YAML文件。我找不到的是我该怎么办?如何制作列表或字典,以便将创建YAML文件?如何使其识别列名,然后浏览行(我应该制作两个单独的词典?)。我没有这样的经验,所以我有点迷路了:)。

示例Excel Row-使用|作为

Metric group|   Metric |    Official business definition |  Preliminary simplistic |description |   Official team ownership (department - tribe)|   Proposed ownership (department - tribe) |   Team lead / Analytics lead |    Slack channel | Last update (person) |  Last update (date) |    Metric versions Dimensionality |    Data source (DB) |  Looker Data model availability |    Looker Data model name| Source of truth |   Target / Threshold |    Slack channel for notifications |Trading impact |Trading impact - quantified|   Useful links                                    

到目前为止的定界符

import gspread
import PyYAML

#service_account authorization
gc = gspread.service_account()

#add here google sheet url/id or name
sh = gc.open_by_url('https://docs.google.com/spreadsheets/MYSPREADSHIT')

#test worksheet_list
#worksheet_list = sh.worksheets()

#test reading
print(sh.worksheet("Product/Business metrics v2").get('B3'))

could you please help? I have a task to copy metrics from google sheet to yaml file(one row = one metric = can be one separate yaml file).
I found out I can use gspread to read data from gsheet and PyYAML yaml.dump to create the yaml file. What I cant find out is actually how can I do that? How to make a list or dictionary so the yaml file will be created? How to make it to recognize column names and then go through rows(should I make two separate dictionaries? ). I have no experience with something like this so I am little bit lost:).

Example excel row - using | as delimiter

Metric group|   Metric |    Official business definition |  Preliminary simplistic |description |   Official team ownership (department - tribe)|   Proposed ownership (department - tribe) |   Team lead / Analytics lead |    Slack channel | Last update (person) |  Last update (date) |    Metric versions Dimensionality |    Data source (DB) |  Looker Data model availability |    Looker Data model name| Source of truth |   Target / Threshold |    Slack channel for notifications |Trading impact |Trading impact - quantified|   Useful links                                    

My code so far

import gspread
import PyYAML

#service_account authorization
gc = gspread.service_account()

#add here google sheet url/id or name
sh = gc.open_by_url('https://docs.google.com/spreadsheets/MYSPREADSHIT')

#test worksheet_list
#worksheet_list = sh.worksheets()

#test reading
print(sh.worksheet("Product/Business metrics v2").get('B3'))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文