We can use the to_csv() function to save a DataFrame to a text or csv file. For example, to save the DataFrame ResultDF created in the previous section; we can use the following statement
>>> ResultDF
>>> ResultDF.to_csv(path_or_buf='C:/images/
resultout.csv', sep=',')
This creates a file by the name resultout.csv in the folder C:/images on the hard disk. When we open this file in any text editor or a spreadsheet, we will find the above data along with the row labels and the column headers, separated by comma.
In case we do not want the column names to be saved to the file we may use the parameter header=False. Another parameter index=False is used when we do not want the row labels to be written to the file on disk.
For example:
>>> ResultDF.to_csv( 'C:/images/resultonly.txt',
sep = '@', header = False, index= False)
If we open the file resultonly.txt, we will find the following contents:
90@92@89@81@94
91@81@91@71@95
97@96@88@67@99