【问题标题】:GBQ | Python: How can I retrieve data types of all the columns in a table?国标| Python:如何检索表中所有列的数据类型?
【发布时间】:2018-02-18 23:55:21
【问题描述】:

我已经使用下面的代码来获取列列表,它工作正常。

table_ref = dataset_ref.table(table_name)
table = client.get_table(table_ref)
field_names = [field.name for field in table.schema]

但是当我尝试下面的代码来获取数据类型时,我收到了一个错误 - AttributeError: 'SchemaField' object has no attribute 'type'

field_types = [field.type for field in table.schema]

【问题讨论】:

    标签: python google-bigquery


    【解决方案1】:

    试试这个:

    field_types = [field.field_type for field in table.schema]
    

    属性名称似乎是 field_type 而不仅仅是“类型”。

    【讨论】:

    • tks,SchemaField.field_type 是我需要的属性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 1970-01-01
    • 2018-04-05
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    相关资源
    最近更新 更多