In this python exercise we are going to see how to parse values from excel and generate multiple files using pandas data frame. This type of scenario is applicable in real time for generating file operations and report generations.
Code used in the video is copied below..
Your feedback and comments are welcome.
Code starts ####
import pandas as pd
import os
ospath = os.chdir('F:\\technolazy\\python')
dir = os.listdir(ospath)
df = pd.read_excel('Excellist.xlsx')
for index,row in df.iterrows():
dept = row["Dept"]
emp_cnt = row["employee_count"]
exp = row["expense"]
print(dept,emp_cnt,exp)
file_name = dept+'.txt'
with open(file_name,'w')as fout:
with open('sampletext.txt','r') as template:
template_read = template.read()
replace_template = template_read.replace('Dept',dept).replace('employee_count',str(emp_cnt)).replace('expense',str(exp))
fout.write(replace_template)
#### Code ends ###
#python exercises
#python learning
#python file handling
#python exercises
On this page of the site you can watch the video online Python Exercise #8 | How to parse values from excel and generate multiple files with a duration of hours minute second in good quality, which was uploaded by the user Technolazy 16 August 2020, share the link with friends and acquaintances, this video has already been watched 14 times on youtube and it was liked by 0 viewers. Enjoy your viewing!