如何使用Python将数据从Gsheet复制到YAML?
你能帮忙吗?我有一项任务将指标从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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论