Tkinter Read file to create Pandas DataFrame

Tkinter Projects in Tkinter Pandas


Tkinter Pandas DataFrame
Use the file browser to connect to any csv ( Comma Separated value ) file on click of a button. Use the read_csv() method to create a Pandas Dataframe by using the selected csv file.

After creation of Dataframe , display the number of rows and columns in the dataframe by using DataFrame attribute shape.
import pandas as pd
import tkinter  as tk 
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfile
my_w = tk.Tk()
my_w.geometry("400x300")  # Size of the window 
my_w.title('www.plus2net.com')

my_font1=('times', 12, 'bold')
l1 = tk.Label(my_w,text='Read File & create DataFrame',
    width=30,font=my_font1)  
l1.grid(row=1,column=1)
b1 = tk.Button(my_w, text='Browse File', 
   width=20,command = lambda:upload_file())
b1.grid(row=2,column=1) 
t1=tk.Text(my_w,width=40,height=5)
t1.grid(row=3,column=1,padx=5)

def upload_file():
    f_types = [('CSV files',"*.csv"),('All',"*.*")]
    file = filedialog.askopenfilename(filetypes=f_types)
    l1.config(text=file) # display the path 
    df=pd.read_csv(file) # create DataFrame
    str1="Rows:" + str(df.shape[0])+ "\nColumns:"+str(df.shape[1])
    #print(str1)
    t1.insert(tk.END, str1) # add to Text widget
my_w.mainloop()  # Keep the window open

Projects in Tkinter
Create Pandas DataFrame by reading Google Analytics csv file from Tkinter GUI

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer