
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Working with Pandas and XlsxWriter
Python Pandas is a data analysis library. It can read, filter and re-arrange small and large datasets and output them in a range of formats including Excel.
Pandas writes Excel files using the XlsxWriter modules.
XlsxWriter is a Python module for writing files in the XLSX file format. It can be used to write text, numbers, and formulas to multiple worksheets. Also, it supports features such as formatting, images, charts, page setup, auto filters, conditional formatting and many others.
Example
# import pandas as pd import pandas as pd # Create some Pandas dataframes from some data. df1 = pd.DataFrame({'Data': [11, 12, 13, 14]}) df2 = pd.DataFrame({'Data': [21, 22, 23, 24]}) df3 = pd.DataFrame({'Data': [31, 32, 33, 34]}) df4 = pd.DataFrame({'Data': [41, 42, 43, 44]}) # Create a Pandas Excel writer object using XlsxWriter as the engine. writer = pd.ExcelWriter('pandas_positioning.xlsx', engine ='xlsxwriter') # write and Positioning the dataframes in the worksheet. # Default position, cell A1. df1.to_excel(writer, sheet_name ='Sheet1') df2.to_excel(writer, sheet_name ='Sheet1', startcol = 3) df3.to_excel(writer, sheet_name ='Sheet1', startrow = 6) # It is also possible to write the dataframe without the header and index. df4.to_excel(writer, sheet_name ='Sheet1', startrow = 7, startcol = 4, header = False, index = False) # Close the Pandas Excel writer object and output the Excel file. writer.save()
- Related Questions & Answers
- Working with Dates and Times in Python
- Working with Images in Python?
- Python - Working with .docx module
- Python - Plotting an Excel chart with Gradient fills using XlsxWriter module
- Working with zip files in Python
- Working with PDF files in Python?
- Python - Working with buttons in Kivy
- Create and write on excel file using xlsxwriter module in Python
- Python - Plotting charts in excel sheet with Data Tools using XlsxWriter module
- Working with csv files in Python Programming
- Python - Working with PNG Images using Matplotlib
- Working with Hashtable and Dictionary in C#
- Working with lists and keys in React.js
- Python - Plotting an Excel chart with pattern fills in column using XlsxWriter module
- Android working with Card View and Recycler View
Advertisements