如何使用熊猫读取文本文件作为输入并写入 excel 列?

How to Read Text file as input and write into excel columns using panda?

我正在使用 permission.txt 文件作为输入,并希望将数据写入 excel -2007 的列(我正在使用 panda XlsxWriter,因为我想要超过 256 列)。 I want to write like this into excel file。我已经尝试按照代码将数据写入行而不是我想将数据写入列(第 1 列,第 2 列......第 400 列)。

import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
import numpy as np


data = pd.read_csv('F:/Research_Work/python/Permission.txt', sep=" ", header=None)
writer = ExcelWriter('Example2.xlsx')
data.to_excel(writer,'Sheet1',index=False)

您可以像这样转置数据帧数据:

import pandas as pd

# Create a Pandas dataframe from some data.
df1 = pd.DataFrame({'Data': [10, 20, 30, 40]})
df2 = df1.T

# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')

# Write the data in column and transposed (row) directions.
df1.to_excel(writer, sheet_name='Sheet1', 
             startrow=1, startcol=1, header=False, index=False)

df2.to_excel(writer, sheet_name='Sheet1', 
             startrow=1, startcol=3, header=False, index=False)

# Close the Pandas Excel writer and output the Excel file.
writer.save()

输出: