You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Python Pandas DateTime对象转换为纯字符串值

你当前得到的输出是长度为1的Series对象,只需要提取该对象的首个元素即可得到纯字符串,有以下几种常用实现方式:

  • 按位置取Series元素,兼容性最强:
report_date = df['Report Date'].dt.strftime('%Y-%m-%d').iloc[0]
  • 先转为numpy数组再取值:
report_date = df['Report Date'].dt.strftime('%Y-%m-%d').to_numpy()[0]
  • 更高效的写法:先取单元格的datetime标量再格式化,不需要对整列做向量化转换:
report_date = df['Report Date'].iloc[0].strftime('%Y-%m-%d')

内容的提问来源于stack exchange,提问作者Rockport Redfish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 02:06:04