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 pdimport pandas as pd  # List initializationlist1 = ['Assam', 'India',         'Lahore', 'Pakistan',          'New York', 'USA',         'Bejing', 'China']  df = pd.DataFrame()  # Creating two columnsdf['State'] = list1[0::2]df['Country'] = list1[1::2]  # Converting to exceldf.to_excel('result.xlsx', index = False) |
Output :


… [Trackback]
[…] Find More here on that Topic: geeksforgeeks.org/python-split-given-list-and-insert-in-excel-file/ […]