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

如何将指定结构的pandas Series转换为目标格式DataFrame

解决方案

你之前使用的两种方法都会生成单列表格,原Series的索引会作为输出DataFrame的行索引,和你需要的「原索引作为列名、所有值放在同一行」的结构行列倒置,只需追加转置操作即可实现需求:

  1. (可选)过滤掉不需要的Unnamed: 0对应行:
series = series.drop("Unnamed: 0")
  1. 转置得到目标格式DataFrame:
df = series.to_frame().T
# 等价写法
df = pd.DataFrame(series).T

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 11:39:04