AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1887966
Accepted
Tiago Peres
Tiago Peres
Asked: 2025-03-22 20:16:22 +0800 CST2025-03-22 20:16:22 +0800 CST 2025-03-22 20:16:22 +0800 CST

将 CSV 体重数据导入 Garmin

  • 772

我从 2020 年开始使用智能秤,它有自己的应用程序,最终成为 Zepp Life。

不久前购买了 Garmin,如果丢失了所有数据,那就太可惜了。

好消息是,我们可以在导入页面中将其他帐户或活动追踪器的数据拉入 Garmin Connect。

因此,我将 Body 数据从 Zepp Life 导出为 CSV。

数据如下

time,weight,height,bmi,fatRate,bodyWaterRate,boneMass,metabolism,muscleRate,visceralFat
2020-09-01 08:00:17+0000,83.6,186.0,24.1,0.0,0.0,0.0,0.0,0.0,0.0
2020-09-01 22:02:16+0000,82.8,186.0,23.9,0.0,0.0,0.0,0.0,0.0,0.0

尝试导入后,发现 Garmin 不支持上传该文件。

那么出现的问题是,CSV 需要哪种格式才能将其上传到 Garmin?

csv
  • 1 1 个回答
  • 44 Views

1 个回答

  • Voted
  1. Best Answer
    Tiago Peres
    2025-03-22T20:16:22+08:002025-03-22T20:16:22+08:00

    感谢 Reddit 上的某人,发现了类似的东西

    Body
    weight,bmi,fat,date,time
    83.6,24.1,0.0,2020-09-01,08:00:17
    82.8,23.9,0.0,2020-09-01,22:02:16
    

    最后也在这里找到了。

    因此,最初创建了一个简单的 Python 脚本,从“zep_life.csv”文件中读取体重和身体成分数据,并将其转换为可导入 Garmin 的 CSV 格式

    这次我不再收到警告,但它卡住了

    图像

    就好像什么都没发生过一样。

    我认为这与文件的大小有关。

    因此,我不再只生成一个文件,而是每年生成一个文件,而且效果很好。

    图像

    这是使用的脚本

    import csv
    import datetime
    
    INPUT_CSV = "zep_life.csv"
    
    def zep_to_garmin_csv():
        """
        Reads a CSV file named "zep_life.csv" and writes multiple yearly CSVs named
        "garmin_ready_<year>.csv". Each output file has the first line "Body", 
        followed by "weight,bmi,fat,date,time" as headers. Rows are based on the 
        'time' field in the input, split by year.
    
        Usage:
            1. Place "zep_life.csv" in the same directory as this script.
            2. Run this script.
            3. For each year encountered in "zep_life.csv", a file named 
               "garmin_ready_<year>.csv" will be created.
    
        Requirements:
            - The input CSV must have the columns: "time", "weight", "bmi", "fatRate".
            - "time" must be in a format parseable by datetime.strptime with 
              "%Y-%m-%d %H:%M:%S%z".
            - "fatRate" of "null" or empty is replaced with "0.0".
        """
        yearly_writers = {}
        with open(INPUT_CSV, mode="r", encoding="utf-8-sig") as fin:
            reader = csv.DictReader(fin)
            for row in reader:
                raw_time = row.get("time", "").strip()
                weight_str = row.get("weight", "").strip()
                bmi_str = row.get("bmi", "").strip()
                fat_str = row.get("fatRate", "").strip()
                
                if not raw_time or not weight_str:
                    continue
    
                try:
                    dt = datetime.datetime.strptime(raw_time, "%Y-%m-%d %H:%M:%S%z")
                except ValueError:
                    continue
    
                date_str = dt.strftime("%Y-%m-%d")  # "YYYY-MM-DD"
                time_str = dt.strftime("%H:%M:%S")  # "HH:MM:SS"
                
                if fat_str.lower() in ("null", ""):
                    fat_str = "0.0"
    
                # If we haven't opened a file for this year yet, do so and write headers.
                year = dt.year
                if year not in yearly_writers:
                    fout = open(f"garmin_ready_{year}.csv", "w", newline="", encoding="utf-8")
                    writer = csv.writer(fout)
                    
                    # First line: "Body"
                    writer.writerow(["Body"])
                    
                    # Second line: headers
                    writer.writerow(["weight", "bmi", "fat", "date", "time"])
                    
                    # Store it in the dictionary
                    yearly_writers[year] = (fout, writer)
    
                # Write the row to the proper year's CSV.
                _, csv_writer = yearly_writers[year]
                csv_writer.writerow([weight_str, bmi_str, fat_str, date_str, time_str])
    
        # Close all the files
        for fout, _ in yearly_writers.values():
            fout.close()
    
        print("Done! Split files by year.")
    
    
    if __name__ == "__main__":
        zep_to_garmin_csv()
    
    • 0

相关问题

  • Powershell ConvertTo-Csv 破坏对象

  • 创建一个带有 Excel 永远不会删除的前导零的 CSV 文件

  • 在 Notepad++ 中是否可以搜索包含太多或太少特定分隔符实例的行?

  • 数字:使用不同的分隔符导出 CSV

  • 计算文本字符串中的逗号并添加新行

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve