gpt4 book ai didi

python - 如何在 Python 中使用 pandas 编写数据数组以在行中而不是在列中表现出色

转载 作者:太空宇宙 更新时间:2023-11-04 09:49:03 24 4
gpt4 key购买 nike

a= [1,2,3,4,5]
df=DataFrame(a)

.... #setup excelwriter 和数据框

df.to_excel(writer, sheet_name=sheetname,startrow=1, startcol=1, header=False, index=False)

输出:

1\n
2\n
3\n
4\n
5

我怎样才能得到输出:

1    2    3    4    5

最佳答案

可以先转置,再保存到excel:

df

0
0 1
1 2
2 3
3 4
4 5

df.T.to_excel(writer,
sheet_name=sheetname,
startrow=1,
startcol=1,
header=False,
index=False)

1   2   3   4   5

关于python - 如何在 Python 中使用 pandas 编写数据数组以在行中而不是在列中表现出色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48613158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com