【问题标题】:Python 3.7 simple_smartsheet, sheet.make_cell -> date error when uploading date and time to Smartsheet JSON Error PandaPython 3.7 simple_smartsheet, sheet.make_cell -> 将日期和时间上传到 Smartsheet JSON 错误 Panda 时出现日期错误
【发布时间】:2021-01-02 11:48:03
【问题描述】:

出现 JSON 错误:TypeError: 时间类型的对象不是 JSON 可序列化的

如何使用 sheet.make_cell 命令成功地将日期列包含在一行中?没有 JSON 错误(上图)?

  1. 运行 Python 3.7

  2. 进口: 导入日志

导入 csv

导入操作系统

将熊猫导入为 pd

从日期时间导入日期

  1. 使用 Panda 语句读取 Excel 文件:

data = pd.read_excel('/home/pi/Documents/tscripts/Sample.xlsx',header = 0 ) df = pd.DataFrame(数据)*

  1. Panda 的输出读取上述 Excel 文件命令:

Excel 文件[[Timestamp('2020-09-05 09:08:00'), datetime.time(9, 8, 39), ' College_of_the_Desert_to_PDC_HUB', 30 , 14, 15, 16, 17, 18, 19, 'CCC-1494']]*

  1. For 循环构建一行。 JSON 错误位于 sheet.make_cell("MyDate", element[1]) 语句中。下面是 for 循环的复制/粘贴。所有其他 sheet.make_cell 命令均成功并作为一行添加到我的 Smartsheet。

发生 JSON 错误的 for 循环中的行列分配 new_rows = []

示例中的元素:

row = Row(to_top=True,strong text

    cells=[

         sheet.make_cell("ccc_key_id", element[10]),

         sheet.make_cell("CCD", element[2]),

         sheet.make_cell("Max_In_Only", element[6]),

         sheet.make_cell("Max_Out_Only", element[9]),

         sheet.make_cell("avg_in_out_max", element[3]),

         sheet.make_cell("MyDate", element[1])  **<<== Result's in a JSON error ** 
    ])

new_rows.append(row)

smartsheet.sheets.add_rows(sheet.id, new_rows)

  1. Smartsheet 中的 MyDate 列可以定义为 Date 或 Text-Number,但仍会导致 JSON 错误。

在互联网上查找并找不到任何帮助。感谢任何帮助。

【问题讨论】:

    标签: python json excel pandas smartsheet-api


    【解决方案1】:

    我使用了不正确的索引号。应该是“0”而不是“1”。 Grr。应该看过。

    【讨论】:

      猜你喜欢
      • 2022-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-26
      • 2019-09-25
      • 1970-01-01
      • 2022-01-17
      相关资源
      最近更新 更多