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

如何从Pandas DataFrame中提取单行并生成指定结构的新DataFrame

你可以直接用iloc取第一行后调用to_frame方法一步实现:

new_df = df.iloc[0].to_frame(name='row')

如果你更习惯手动构造的方式,也可以这么写:

new_df = pd.DataFrame({'row': df.iloc[0].tolist()})

两种方法输出的new_df都符合你需要的结构:

row
0    0
1    2
2    5
3    3

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.23 21:24:05