pandas xlsxwriter,无法使用 xlsxwriter 转换 columns/row
pandas xlsxwriter, not able to shift columns/row using xlsxwriter
我一直在尝试在将数据导出到 excel sheet 时移动行和列,但无法做到这一点。我写了下面的代码-
import pandas as pd
writer = pd.ExcelWriter(filename, engine='xlsxwriter')
workbook = writer.book
df.to_excel(writer, index=False, sheet_name='mydata')
worksheet = writer.sheets['Index Levels']
writer.save()
知道怎么做吗?
在将数据帧写入 sheet 之前,您是否尝试过转置数据帧?
df1_transposed = df1.T
这将切换行和列
如果这不是您想要的,请进一步解释什么是“转移”
我认为你可以明确提及行和列,如下所示
df.to_excel(writer, index=False, sheet_name='mydata', startcol=value,
startrow=value)
请参考https://xlsxwriter.readthedocs.io/working_with_pandas.html
你会找到下面提到的解决方案
# Position the dataframes in the worksheet.
df1.to_excel(writer, sheet_name='Sheet1') # Default position, cell A1.
df2.to_excel(writer, sheet_name='Sheet1', startcol=3)
df3.to_excel(writer, sheet_name='Sheet1', startrow=6)
我一直在尝试在将数据导出到 excel sheet 时移动行和列,但无法做到这一点。我写了下面的代码-
import pandas as pd
writer = pd.ExcelWriter(filename, engine='xlsxwriter')
workbook = writer.book
df.to_excel(writer, index=False, sheet_name='mydata')
worksheet = writer.sheets['Index Levels']
writer.save()
知道怎么做吗?
在将数据帧写入 sheet 之前,您是否尝试过转置数据帧?
df1_transposed = df1.T
这将切换行和列
如果这不是您想要的,请进一步解释什么是“转移”
我认为你可以明确提及行和列,如下所示
df.to_excel(writer, index=False, sheet_name='mydata', startcol=value,
startrow=value)
请参考https://xlsxwriter.readthedocs.io/working_with_pandas.html 你会找到下面提到的解决方案
# Position the dataframes in the worksheet.
df1.to_excel(writer, sheet_name='Sheet1') # Default position, cell A1.
df2.to_excel(writer, sheet_name='Sheet1', startcol=3)
df3.to_excel(writer, sheet_name='Sheet1', startrow=6)