Python Forum
Python code to set column width
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python code to set column width
#1
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.

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
Reply


Messages In This Thread
Python code to set column width - by 1418 - Jan-14-2024, 03:31 AM
RE: Python code to set column width - by Larz60+ - Jan-14-2024, 04:47 AM
RE: Python code to set column width - by 1418 - Jan-14-2024, 05:01 AM
RE: Python code to set column width - by sgrey - Jan-14-2024, 05:44 AM
RE: Python code to set column width - by 1418 - Jan-14-2024, 06:22 AM
RE: Python code to set column width - by sgrey - Jan-14-2024, 07:05 AM
RE: Python code to set column width - by 1418 - Jan-14-2024, 07:41 AM
RE: Python code to set column width - by sgrey - Jan-14-2024, 07:48 AM
RE: Python code to set column width - by 1418 - Jan-14-2024, 07:52 AM
RE: Python code to set column width - by sgrey - Jan-14-2024, 07:56 AM
RE: Python code to set column width - by 1418 - Jan-20-2024, 04:48 AM
RE: Python code to set column width - by Pedroski55 - Jan-20-2024, 07:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fixed colum width for rowLabels i Matplotlib pandabay 0 444 Jun-10-2023, 03:40 PM
Last Post: pandabay
  Code for pullng all data in a column EmBeck87 5 1,180 Apr-03-2023, 03:43 PM
Last Post: deanhystad
  Reshaping a single column in to multiple column using Python sahar 7 2,123 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  width of Unicode character Skaperen 6 2,799 Sep-27-2021, 12:41 AM
Last Post: Skaperen
  image.thumbnail(width, height) not working PCesarano 2 3,480 Apr-08-2021, 06:09 PM
Last Post: PCesarano
  How can I get the width of a string in Python? aquerci 14 16,340 May-27-2019, 06:00 PM
Last Post: heiner55
  fixed width numbers Skaperen 15 8,783 May-27-2019, 09:42 AM
Last Post: Skaperen
  Code snippets for building multi column Listviews and or Treeview KevinBrown 3 3,345 Apr-14-2019, 06:50 PM
Last Post: Yoriz
  printing text tables with consistent width Skaperen 7 10,758 Jul-01-2018, 02:34 AM
Last Post: Skaperen
  How to measure an inclined beam width and height in image using python? zyb1003 1 3,265 Nov-07-2017, 05:02 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020