pandas - 使用 pandas 将时间戳插入 bigquery 表
问题描述
我在 Google bigquery 中有一个表,其中一列设置为数据类型时间戳。
我必须使用熊猫的 to_gbq 函数插入数据。
如果我将数据类型设置为字符串而不是时间戳,则数据将加载到表中。
但我希望该列是时间戳数据类型。
如何将数据框的列类型转换为与 Google bigquery 兼容的时间戳。
错误
表架构
解决方案
Timestamp is stored as int64
datatype, or int
, so if you would like to format it in such a way, you can store cast your column to this datatype in pandas.
import numpy as np
import pandas as pd
df.COLUMN_OBJECT = df.COLUMN_OBJECT.astype(np.int64)
df.COLUMN_DATETIME = df.COLUMN_DATETIME.apply(lambda x: x.timestamp).astype(np.int64)
You can have the timestamp in seconds, ms, or ns.
推荐阅读
- python - 在数据框列上应用函数以获取其他几个列 Pandas Python
- xamarin - 我想在 xaml 中使用按钮获取参数
- python - 为什么这两个 numpy 数组分配有区别?
- amazon-web-services - 用于 jumpbox 的 AWS CloudFormation 用户数据
- python - 如何从一列文本观察中删除没有任何意义的单词
- python - 平均成绩和“如果”
- ibm-odm - IBM ODM 无法生成有效的 WADL
- spacy - spacy.matcher.PhraseMatcher object has no attribute "remove"
- flutter - 如何从 StreamBuilder 'Cloud Firestore' 正确显示单个值
- visual-studio-code - VS Code:深度链接扩展