Python Exercise #8 | How to parse values from excel and generate multiple files

Publié le: 16 août 2020
sur la chaîne: Technolazy
14
0

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


Sur cette page du site, vous pouvez voir la vidéo en ligne Python Exercise #8 | How to parse values from excel and generate multiple files durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Technolazy 16 août 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 14 fois et il a aimé 0 téléspectateurs. Bon visionnage!