Thursday, October 2, 2025
HomeLanguagesPython | Split given list and insert in excel file

Python | Split given list and insert in excel file

Given a list containing Names and Addresses consecutively, the task is to split these two elements at a time and insert it into excel.

We can use a very popular library for data analysis, Pandas. Using pandas we can easily manipulate the columns and simply insert the filtered elements into excel file using df.to_excel() function.

Below is the implementation :




# Python code to split the list two element 
# at a time and insert it into excel.
  
# Importing pandas as pd
import pandas as pd
  
# List initialization
list1 = ['Assam', 'India',
         'Lahore', 'Pakistan'
         'New York', 'USA',
         'Bejing', 'China']
  
df = pd.DataFrame()
  
# Creating two columns
df['State'] = list1[0::2]
df['Country'] = list1[1::2]
  
# Converting to excel
df.to_excel('result.xlsx', index = False)


Output :

RELATED ARTICLES

Most Popular

Dominic
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11926 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7079 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS