0

I have a long matrix (say A) with 10,000 rows and 2 columns in an excel file.

I need to copy each column in separate text files (say A0.txt, A1.txt);

I did the following

A0 = open("A0.txt", "w+")
A1 = open("A1.txt", "w+")
A0.write(A.iloc[:,0])
A1.write(A.iloc[:,1])

but the error is

TypeError: write() argument must be str, not Series

then, how can I write the series?

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
hanugm
  • 1,127
  • 3
  • 13
  • 44

1 Answers1

3

You could do something like:

for col in A.columns:
    A[col].to_csv('A_'+col+'.txt', index=False, header=False)

and you will end up with one txt file per column.

Mateo Torres
  • 1,545
  • 1
  • 13
  • 22