T
T
Tem4ikArtem4ik2021-05-25 09:30:46
Python
Tem4ikArtem4ik, 2021-05-25 09:30:46

How to stretch column widths in Excel using Pandas?

There is this code:

import pandas as pd
from tkinter import *
from time import gmtime, strftime

def write():
    lasname = str(lastnameentry.get())
    lastlastname = str(lastlastnameentry.get())
    birthday = str(birthdayentry.get())
    name = str(nameentry.get())
    df = pd.read_excel('list.xlsx', engine='openpyxl')
    df = df.replace('%lastname%', lasname)
    df = df.replace('%lastlastname%', lastlastname)
    df = df.replace('%birth%', birthday)
    df = df.replace('%name%', name)
    date = strftime("%d-%m-%Y", gmtime())
    filename = name+' '+lasname+' '+date+'.xlsx'
    df.to_excel(filename, index=False)


#Tkinter
root = Tk()
root.geometry('500x500')
root.title('Write Excel')
root.resizable(width=False, height=False)

namelabel = Label(root, text='Имя:', font='Arial 25')
nameentry = Entry(root, font='Arial 25')
lastnamelabel = Label(root, text='Фамилия:', font='Arial 25')
lastnameentry = Entry(root, font='Arial 25')
lastlastnamelabel = Label(root, text='Отчество:', font='Arial 25')
lastlastnameentry = Entry(root, font='Arial 25')
birthdaylabel = Label(root, text='Дата рождения:', font='Arial 25')
birthdayentry = Entry(root, font='Arial 25')
writebutton = Button(root, text='Записать', command=write, font='Arial 25')

namelabel.pack()
nameentry.pack()
lastnamelabel.pack()
lastnameentry.pack()
lastlastnamelabel.pack()
lastlastnameentry.pack()
birthdaylabel.pack()
birthdayentry.pack()
writebutton.pack()

root.mainloop()

After its execution, the following table is obtained:
60ac987527698208323074.png
Information is cut off at the edges. There is an option using Pandas to stretch the fields so that it looks like this:
60ac997be7438972297477.png
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zexer, 2021-05-25
@Tem4ikArtem4ik

https://towardsdatascience.com/how-to-auto-adjust-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question