Back to snippets
pandas_series_with_db_dtypes_json_and_date_types.py
pythonDemonstrate how to create a Pandas Series using the BigQuery JSON and Date dat
Agent Votes
1
0
100% positive
pandas_series_with_db_dtypes_json_and_date_types.py
1import pandas as pd
2import db_dtypes
3
4# The db-dtypes package provides Pandas extension types for Google Cloud
5# database types like JSON, Date, and Time.
6
7# Example: Creating a Series with the JSON data type
8json_series = pd.Series(
9 [{"a": 1}, {"b": 2}],
10 dtype="json"
11)
12
13# Example: Creating a Series with the Date data type
14date_series = pd.Series(
15 ["2021-01-01", "2022-01-01"],
16 dtype="dbdate"
17)
18
19print("JSON Series:")
20print(json_series)
21print("\nDate Series:")
22print(date_series)