Skip to content
Advertisement

How to get a user input for a column in pandas by creating a GUI using tkinter?

I have a dataframe with 3 columns: Date, attribute_one, attribute_two. The date column is blank but the other two columns are filled with some data. how can I use tkinter package to build a GUI which would prompt the user to enter date which will then be eventually stored in the dataframe.

Advertisement

Answer

Using the tkinter Entry class, and using a list, you can easily accomplish so.

from tkinter import *

tk = Tk()

def add_data():
   o = i.get()
   code = o
   print(code)

i = Entry(tk)

i.pack()

code = str()

btn = Button(tk, command = add_data, text='Add')

i.pack()

btn.pack()

You can then add it to the column. If you want to ask them in the console, use this instead:

import sys

print('Please enter the date.')

i = str(sys.stdin.readline())

print(i)

Then just add the variable i to your dataframe.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement