Jan-14-2024, 03:31 AM
Hi, I have tried several codes to set my column widths without success. Is there a simple code similar to VBA I could use?
I would like to add column widths to the code I am building below. Do I need to 'import numpy as np' or anything else?
Please let me know of any other improvements I can make to my code.
Thanks in advance.
I would like to add column widths to the code I am building below. Do I need to 'import numpy as np' or anything else?
Please let me know of any other improvements I can make to my code.
Thanks in advance.
import pandas as pd inspdata=pd.read_excel('Inspections data.xlsx') #remove columns inspdata.drop(['Notice Creation','count()'],axis=1, inplace=True) #replace header row names inspdata.columns=['EForm ID','Contractor','Address','Area','Classification','Program','Notice Ref #','Category','Inspection Type', 'Result','Actual Date','Created Date','Status','CIO','PO'] #delete first 4 rows below the header inspdata.drop([0,1,2,3],axis=0,inplace=True) #keeps header row #replace text inspdata['Classification'].replace(['VACQREP','VACAP'],['VAC','VAC'],inplace=True) print(inspdata.head(10)) inspdata.to_excel('Inspections Data Python.xlsx',index=False)Is there a simple Python code similar to the below VBC code?
'VBA code to format column widths Range("A1").ColumnWidth = 15 Range("B1").ColumnWidth = 30