C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Pandas DataFrame.to_excel()We can export the DataFrame to the excel file by using the to_excel() function. To write a single object to the excel file, we have to specify the target file name. If we want to write to multiple sheets, we need to create an ExcelWriter object with target filename and also need to specify the sheet in the file in which we have to write. The multiple sheets can also be written by specifying the unique sheet_name. It is necessary to save the changes for all the data written to the file. Note: If we create an ExcelWriter object with a file name that already exists, it will erase the content of the existing file.SyntaxDataFrame.to_excel(excel_writer, sheet_name='Sheet1', na_rep='', float_format=None, columns=None, header=True, index=True, index_label=None, startrow=0, startcol=0, engine=None, merge_cells=True, encoding=None, inf_rep='inf', verbose=True, freeze_panes=None) Parameters
Exampleimport pandas as pd # create dataframe info_marks = pd.DataFrame({'name': ['Parker', 'Smith', 'William', 'Terry'], 'Maths': [78, 84, 67, 72], 'Science': [89, 92, 61, 77], 'English': [72, 75, 64, 82]}) # render dataframe as html writer = pd.ExcelWriter('output.xlsx') info_marks.to_excel(writer) writer.save() print('DataFrame is written successfully to the Excel File.') Output DataFrame is written successfully to the Excel file
Next TopicDataFrame.transform()
|