{"id":27026,"date":"2022-04-08T23:41:31","date_gmt":"2022-04-08T18:11:31","guid":{"rendered":"https:\/\/python-programs.com\/?p=27026"},"modified":"2022-04-08T23:41:31","modified_gmt":"2022-04-08T18:11:31","slug":"split-a-given-list-and-insert-in-excel-file-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/split-a-given-list-and-insert-in-excel-file-in-python\/","title":{"rendered":"Split a Given List and Insert in Excel File in Python"},"content":{"rendered":"
In this article, let us see how to split a given list and insert it into an excel file using Python.<\/p>\n
In Python, how do you split a list?<\/p>\n
We can split the given list of elements using slicing.<\/p>\n
Pandas Module in Python:<\/strong><\/p>\n Pandas is an open-source library designed to make it simple and natural to work with relational or labeled data. It includes a number of data structures and methods for working with numerical data and time series. This library is based on the NumPy Python library. Pandas is quick and has a high level of performance and productivity for its users.<\/p>\n Pandas is widely used for data science, data analysis, and machine learning activities. It is built on top of Numpy, a library that supports multi-dimensional arrays. Pandas, as one of the most popular data-wrangling programs, is normally included in every Python distribution, from those that come with your operating system to commercial vendor versions like ActiveState’s ActivePython.<\/p>\n Using pandas, we can easily edit the columns and use the dataframe.to excel() function to quickly insert the filtered elements into an excel file.<\/p>\n The list is converted into data, rows, and columns by using a data frame. We can use the splitter list in an Excel sheet this way.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" In this article, let us see how to split a given list and insert it into an excel file using Python. In Python, how do you split a list? We can split the given list of elements using slicing. Pandas Module in Python: Pandas is an open-source library designed to make it simple and natural …<\/p>\nSplitting a Given List and Insert in Excel File in Python<\/h2>\n
\n
# Import pandas module using the import keyword \r\nimport pandas \r\n# Give the list as static input and store it in a variable.\r\ngvn_lst = [1, 'John','Software developer', 80000,\r\n 2,'Virat', 'Project associate', 50000,\r\n 3, 'Nick','Testing Engineer', 40000,\r\n 4, 'Rosy','Networking department', 35000] \r\n\r\n# Create a dataframe object using the DataFrame() function of the pandas module\r\ndatafrme = pandas.DataFrame() \r\n# Creating 4 columns on the dataframe(Employ_id, Employee_Name, Designation, Salary) \r\n# by applying slicing on the given list\r\ndatafrme['Employ_id'] = gvn_lst[0::4] \r\ndatafrme['Employee_Name'] = gvn_lst[1::4] \r\ndatafrme['Designation'] = gvn_lst[2::4]\r\ndatafrme['Salary'] = gvn_lst[3::4]\r\n\r\n# Save all the above 4 columns of the dataframe into an Excel file using the to_excel()\r\n# function\r\n# Here, the to_excel() function is used to insert an object into an Excel file.\r\ndatafrme.to_excel('OutputExcelFile.xlsx', index = False)<\/pre>\n