Python Forum
export dataframe to file.txt
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
export dataframe to file.txt
#4
It's not a normal dataFrame that easy to export.
To get DataFrame format to a file,can do a tricks bye using .to_clipboard() and catch the output.
# Your DataFrame
>>> cc
           0            1      2      3
0  gridtype=  curvilinear              
1  gridsize=            9              
2     xvals=         -180 -175.0 -170.0
3                    -180 -175.0 -170.0
4                    -180 -175.0 -170.0

>>> cc.to_clipboard(index=False)
>>> ccc = pd.io.clipboard.clipboard_get()
# This is how test.txt will look
>>> print(ccc)
0	1	2	3

gridtype=	curvilinear		

gridsize=	9		

xvals=	-180	-175.0	-170.0

	-180	-175.0	-170.0

	-180	-175.0	-170.0
>>> with open("test.txt", "w") as f:
...     print(ccc, file=f)   
Reply


Messages In This Thread
export dataframe to file.txt - by dramauh - Apr-18-2022, 05:53 AM
RE: export dataframe to file.txt - by snippsat - Apr-18-2022, 11:01 AM
RE: export dataframe to file.txt - by dramauh - Apr-18-2022, 11:56 AM
RE: export dataframe to file.txt - by snippsat - Apr-18-2022, 06:29 PM
RE: export dataframe to file.txt - by dramauh - Apr-19-2022, 02:23 AM
RE: export dataframe to file.txt - by sarahroxon7 - Apr-21-2022, 01:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Export dataframe to xlsx - Error "zipfile.BadZipFile: File is not a zip file" Baggio 10 63,130 Mar-12-2021, 01:02 PM
Last Post: buran
  How to form a dataframe reading separate dictionaries from .txt file? Doug 1 4,302 Nov-09-2020, 09:24 AM
Last Post: PsyPy
  Export Co-ords to CSV file gtbiyb 1 1,911 Sep-19-2019, 07:59 PM
Last Post: j.crater
  How to add a dataframe to an existing excel file wendysling 2 28,306 May-09-2019, 07:00 PM
Last Post: wendysling
  convert images into pixel dataframe into csv file using python synthex 3 17,596 Feb-17-2019, 06:26 AM
Last Post: scidam
  Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 5,631 Oct-18-2018, 09:33 PM
Last Post: volcano63
  access a very large file? As an array or as a dataframe? Angelika 5 5,028 May-18-2017, 08:15 AM
Last Post: Angelika

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020