Projects using Pandas

Storing file name,modification time & size of dirctory in Excel file by using Pandas DataFrame G#01

Store file details against each directory in Excel file

  • Create a list of directory to search
  • Browse through each directory by using Path
  • Create a blank DataFrame with one date column
  • Check the file extension for required file types
  • Collect size, modified date of each file
  • Insert to dataframe against each file name
  • Save the DataFrame with data in excel file.
  • Loop through the next directory and repeat the above steps to store the file details.
import os
from datetime import datetime
import pandas as pd

# source directory list to get list of files
for d in l1:
    path = "C:\\xampp\\htdocs\\dir\\"+d+"\\"  
    f_x='C:\\data2\\'+d+'.xlsx' #path with name, to store final excel file
    df = pd.DataFrame(columns = ['f_name', 'dt', 'size']) #create DF
    df['dt'] = pd.to_datetime(df['dt']) # change to date column
    for f in files:
        t_stamp=os.path.getmtime(path+f) # for file modificaton time
        #t_stamp=os.path.getctime(path) # for file Creation time
            dt_mod = datetime.fromtimestamp(t_stamp) # date object
            #print('File Modified on:', dt_mod)  # Prting date and time
            m_date = datetime.strftime(dt_mod, '%Y-%m-%d') # Change format
            #print(f, f_extension, m_date,size)
            df2 = pd.DataFrame({'f_name': [f], 'dt': [m_date],'size':[size]})
            #df = df.append({'f_name' : f, 'dt' : m_date, 'size' : size},ignore_index = True)
    df.to_excel(f_x,index=False) # create excel file with file data
os : operating system interfaces module

Report on modified files

Report from Excel file using Pandas DataFrame showing files modified using Date period G-02
Using above excel files we can read and generate report showing total files and modified files during a period.
from datetime import datetime
import pandas as pd

for d in l1:
    f_x='C:\\data\\'+d+'.xlsx' # path with file name
    df = pd.read_excel(f_x,index_col='f_name')
    df['dt'] = pd.to_datetime(df['dt'])
    # Total files - : - Number of files modified in year-month
Instead of a perticular month ( 2023-07 ) we can use a range of date to get the output.
    mask = (df['dt'] > '2023-7-1') & (df['dt'] <= '2023-8-10')

Tkiner GUI to select directory and display result

Displaying Report on Tkinter window from Excel file using Pandas DataFrame G#03

Directory browsing and showing result in Tkitner GUI
We can use one GUI Tkinter window with directory browsing to select the directory inside which our above Excel files are located. Using this directory we can collect all information from the excel file and display the result by using Labels.
import os
from datetime import datetime
import pandas as pd
import tkinter as tk
from tkinter import filedialog
my_w = tk.Tk()
my_w.geometry("500x400")  # Size of the window 
my_w.title("")  #  title
font1=('Times',22,'normal') # font family, size, style

def my_fun(): 
    path = filedialog.askdirectory() # select directory 
    lb1.config(text=path) # update the text of Label with directory path
    l1=os.listdir(path) # List of files in directory
    my_row=1 # Starting row number 
    for d in l1:
        f_x=path+'//'+d # path with file name
        df = pd.read_excel(f_x,index_col='f_name')



        my_row=my_row+1 # Go to Next row by adding 1 
b1=tk.Button(my_w,text='Select directory',font=22,


my_w.mainloop()  # Keep the window open

Find out the orphan pages in a directory

A page without any links pointing to it is called an orphan page.
In above code we have created Excel pages for each directory. We are going to use the same file to identify the pages without any incoming link or orphan pages.
Few points to Note.
  • We are checking the files within the same directory. This script will not consider if any incomming link is there from other directory.
  • This program will check for href links only so pages with JavaScript window or pages with FORM action attributes will also appear as orphan page.
Regular Expression is used to get list of URLs in a Page
import re,os
import pandas as pd
l1=['php_tutorial'] # directory list to check 
for d in l1:
    f_x='D:\\data\\'+d+'.xlsx' # get the excel file for the file list 
    df = pd.read_excel(f_x,index_col='f_name')
    path1='C:/xampp/htdocs/z~1234-plus2net/'+d+'/' # dir path
    for file_name_to_check in f_list:
        if(file_name_to_check in file_list):
            #print('File is there, checking')
            for f in file_list:
                if(file_extension=='.php'): # check this extension only
                    fob= open(path1+f,'r',encoding='utf8',errors='ignore')
           # collect data 
                    fob.close() # close file object 
                    urls1 = re.findall(r'href=[\'"]?([^\'" >]+)', data) # list of URLs
                    if(file_name_to_check in urls1):
            print('File is not there, check the list.  ',file_name_to_check)

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    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-2024 All rights reserved worldwide Privacy Policy Disclaimer