Reputation: 89
I have a very wide dataframe, and I need the dtypes of all the columns as a list of dicts:
[{'name': 'col1', 'type': 'STRING'},...]
I need to do that to supply this as the schema for a BigQuery table.
How could that be achieved?
Upvotes: 0
Views: 308
Reputation: 120519
Use a comprehension:
out = [{'name': col, 'type': dtype.name} for col, dtype in df.dtypes.items()]
print(out)
# Output:
[{'name': 'col1', 'type': 'float64'}, {'name': 'col2', 'type': 'float64'}]
Upvotes: 1