Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a data frame file like this:
   x  y  z
0 -1  2 -3
1  4  5  6
2  7  8  9

and I want to convert it into text file where the first row(Header) and the the first column (indices) is removed:
-1  2 -3
 4  5  6
 7  8  9

how can I do this in python?

What I have tried:

I tried df.to_txt but there was no such attribute
Posted
Updated 24-Feb-22 7:32am
Comments
Richard MacCutchan 24-Feb-22 9:41am    
Create a loop that iterates over the rows and columns and prints the frame items.
Maciej Los 24-Feb-22 13:32pm    
My virtual 5!

1 solution

First result from Google: Python, Pandas : write content of DataFrame into text File - Stack Overflow[^]

Python
np.savetxt(r'c:\data\np.txt', df.values, fmt='%d')
 
Share this answer
 
Comments
Andre Oosthuizen 24-Feb-22 15:36pm    
5 Kudos for stating the obvious search result. I soooo wish people put some effort into their question asking! Thanks Maciej
Maciej Los 25-Feb-22 0:41am    
Thank you, Andre.
Youssef Hany 2021 24-Feb-22 16:18pm    
@andre I did searched stack over flow before asking but didn't find that answer:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900