GBQ | Python:如何检索表中所有列的数据类型?

问题描述 投票:1回答:1

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

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

但当我尝试下面的代码来获取数据类型时,我收到一个错误 - AttributeError:'SchemaField'对象没有属性'type'

field_types = [field.type for field in table.schema]
python google-bigquery
1个回答
2
投票

试试这个:

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

因为看起来属性名称是field_type而不仅仅是“类型”。

© www.soinside.com 2019 - 2024. All rights reserved.