如何将熊猫列转换为大查询表日期格式

MT4*_*467 1 python datetime google-bigquery

我有一个带有日期格式列的熊猫数据框,如下所示:

PublishDate= 2018-08-31 我使用panda to_gbq() 函数将数据转储到bigquery 表中。在转储数据之前,我确保列的格式与表方案匹配。发布日期仅是 bigquery 表中的日期。如何实现类似于:

     df['PublishDate'] = df['PublishDate'].astype('?????')
Run Code Online (Sandbox Code Playgroud)

我试过 datetime64[D] 和

     df['PublishDate'] = pd.to_datetime(df['PublishDate'], format='%Y-%m-%d', errors='coerce').dt.date
     df['PublishDate'] = [time.to_date() for time in df['PublishDate']]
Run Code Online (Sandbox Code Playgroud)

但那些没有用!

小智 5

我面临同样的问题

发现根据你可以提供的文档

table_schema : 字典列表,可选

所以在我的情况下添加

table_schema = [{'name':'execution_date','type': 'DATE'}]
Run Code Online (Sandbox Code Playgroud)

工作过

全线:

 pdg.to_gbq(table_for_uploading, upload_table, project_id=project_id, if_exists='replace', credentials=gbq_credentials,table_schema = [{'name':'execution_date','type': 'DATE'}])
Run Code Online (Sandbox Code Playgroud)