Home > Mobile >  Is there a method to change the number format of 100 excel files with 20 sheets each from 2 decimal
Is there a method to change the number format of 100 excel files with 20 sheets each from 2 decimal

Time:07-01

import pandas as pd
import os
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile

path=os.getcwd()
files=os.listdir(path)
for i in range(len(files)):
    filename = files[i]
    filepath=os.path.join(path,filename)
    
print(filepath)
df=pd.ExcelFile(filepath)  # read sheet name 
sheet = df.sheet_names
print(sheet)
df=pd.read_excel(filepath, sheet_name=sheet,skiprows = 5,  nrows=15, usecols = 'E:L')

print(df)

when I click on the number it show 6 digits in the header but I want to change it into the excel also

CodePudding user response:

import openpyxl

wb = openpyxl.load_workbook('ds.xlsx')
ws = wb.active

for row in ws.iter_rows():
    for cell in row:
        # only relevant column and without header
        if cell.column_letter == 'A' and cell.row > 1: # put the cell number from where to where you want to check
            ws[cell.coordinate].number_format = '0.0000000' # it will change the number format

wb.save('ds2.xlsx')
  • Related