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
In questa pagina del sito puoi guardare il video online Python Exercise #8 | How to parse values from excel and generate multiple files della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Technolazy 16 agosto 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 14 volte e gli è piaciuto 0 spettatori. Buona visione!