Split a given list and insert in excel file in Python

In this tutorial, you are going to learn how to split a given list and insert in excel file in Python.

How to Split a list in Python?

Store some data in List and it is splitter into elements by using Pandas.

Program:

import pandas  
list = ['Svr Engineering College', 'BTech','ECE',
         'Geetham University','BE', 'IT',
         'Annamacharya University', 'BTech','EEE',
         'ALFA College','BTech','CSE',
        'RGM College','BE','MECH'] 

data = pandas.DataFrame() 
data['college'] = list1[0::3] 
data['Qualification'] = list1[1::3] 
data['Specialization'] = list1[2::3]

data.to_excel('report.xlsx', index = False) 

Output:

Split a given list and insert in excel file in Python

Explanation:

First import Pandas.

Store some list of data in a list.

Pandas.Dataframe() split the list into three elements.

Here data frame converts the list into data, rows, columns. By this, we can use the splitter list into Excel sheet.

By using data.to_excel() to insert an object into an excel file.

We can find the excel file in space in which the python programs are saved.

import pandas  
list = ['Lion','Cow',
       'Tiger','Buffalo',
       'Leopard','Cat',
       'cheetah','Pig'] 

data = pandas.DataFrame() 
data['Wild Animals'] = list[0::2] 
data['Domestic Animals '] = list[1::2]

data.to_excel('Animals.xlsx', index = False) 

Output:

Split a given list and insert in excel file in Python

Explanation:

This is also similar to the above program.

First import Pandas.

Store some list of data in a list.

Pandas.Dataframe() split the list into two elements.

Here data frame converts the list into data, rows, columns. By this, we can use the splitter list in an Excel sheet.

By using data.to_excel() to insert an object into an excel file.

We can find the excel file in space in which the python programs are saved.

Also read: How to plot pie chart in excel sheet using Python

Leave a Reply

Your email address will not be published. Required fields are marked *