2017-11-30 4 views
0

私はintputとしてpermission.txtファイルを使用していますが、エクセル-2007のカラムにデータを書きたいと思っています(私は256列以上が必要なので、私はpanda XlsxWriterを使用しています)。 I want to write like this into excel file。私は行にデータを書き込む代わりに、列にデータを書きたい(列1、列2 ......列400)コードを次のコードで試してみました。パンダを使用してテキストファイルを入力してExcelの列に書き込む方法は?

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) 

答えて

1

あなたはちょうどこのように、データフレームのデータをトランスポーズできます。

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() 

出力:

enter image description here

+0

おかげで私のためにこの作品。私はテキストファイルを読むために以下を追加しました。 df1 = pd.read_table( 'F:/Research_Work/python/Permission.txt'、delim_whitespace = True)。あなたの答えを加えてください。 –

関連する問題