简体   繁体   中英

How can I automate my code using openpyxl and Pandas?

I have a couple of issues automating my data regarding openpyxl and pandas which is related to the length of the Dataframe DF.

The first one is regarding cells. I want to automate each row in which if it only prints the border in the number of rows equal to the length of the dataframe starting from row 3

       A3 = ws['A3'] 
       A3.border = Border(top=thin, left=thin, right=thin, bottom=thin)
       A3.alignment=Alignment(horizontal='general',
         vertical='bottom',
         text_rotation=0,
         wrap_text=True,
         shrink_to_fit=False,
         indent=0)
       A4 = ws['A4'] 
       A4.border = Border(top=thin, left=thin, right=thin, bottom=thin)
       A4.alignment=Alignment(horizontal='general',
         vertical='bottom',
         text_rotation=0,
         wrap_text=True,
         shrink_to_fit=False,
         indent=0)

The second one is regarding the dataframe. I want according to the length of the dataframe that "None" should be added to the df column a number of times

note =  [None, None, None,None,None,None,None,None]
df['Note'] = note

For the second question, you can simply do, IIUC:

df['Note'] = None

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM