pandas 系列到Excel [英] Pandas Series to Excel
本文介绍了 pandas 系列到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
pandas.Series对象确实有许多to_*
函数,但缺少to_excel
函数.在此代码段的第3行中,是否有更简便/更好的方法来完成导出?仅仅为了简单的I/O,首先将Series转换为DataFrame感觉很麻烦:
The pandas.Series object does have many to_*
functions, yet it lacks a to_excel
function. Is there an easier/better way to accomplish the export in line 3 of this snippet? It feels clunky to first convert the Series to a DataFrame simply for a simple I/O:
import numpy as np
import pandas as pd
s = pd.Series([1,3,5,np.nan,6,8])
pd.DataFrame(s).to_excel('s.xlsx', 's')
推荐答案
您可以:
在这种情况下,您已经回答了自己的问题.
in which case you've already answered your own question.
s.to_frame(name='column_name').to_excel('xlfile.xlsx', sheet_name='s')
这篇关于 pandas 系列到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文