Python 3 Script to Export a Pandas DataFrame to an Excel File Full Project For Beginners

Python 3 Script to Export a Pandas DataFrame to an Excel File Full Project For Beginners

 

Welcome folks today in this tutorial we will be exporting a pandas dataframe to an excel file. The full project source code is given below.

 

 

Get Started

 

 

In order to get started we need to install pandas library by pip command

 

pip install pandas

 

Now make a app.py file and copy paste the following code

 

app.py

 

 

# importing the module 
import pandas as pd 

# creating the DataFrame 
cars_data = pd.DataFrame({'Cars': ['BMW', 'Audi', 'Bugatti', 
                                'Porsche', 'Volkswagen'], 
                        'MaxSpeed': [220, 230, 240, 210, 190], 
                        'Color': ['Black', 'Red', 'Blue', 
                                    'Violet', 'White']}) 

# writing to Excel 
datatoexcel = pd.ExcelWriter('CarsData1.xlsx') 

# write DataFrame to excel 
cars_data.to_excel(datatoexcel) 

# save the excel 
datatoexcel.save() 
print('DataFrame is written to Excel File successfully.')

 

See also  Python 3 Script to Convert C++ Source Code to Python Code Using cpp2python Library Full Project For Beginners

 

 

 

 

Leave a Reply