1

I'm new to Python, so forgive my ignorance I'm using pysimplegui to build a project tracker to help organize my work.

I've tried manually converting each date value within the list, but it tends to print the values incorrectly, and breaks them out of the list, when I'm trying to build the table.

I'm hoping there is a global way to change the date format used from "Timestamp" to "Date" or "Datetime".

My current code:

import PySimpleGUI as sg
import pandas as pd
from datetime import datetime



Excel_Read = pd.read_excel('C:\pythonProject\Schedule\Project_Schedule.xlsx', sheet_name='Schedule')

schedule_headings = ['Priority', 'Project_Name','Project_Num','Due_Date','Sales','Engineer','PM/PC' ]

Schedule_Table = pd.DataFrame(schedule_headings)
Schedule_List = Excel_Read.values.tolist()


def create_schedule(schedule_info_array, schedule_headings):
    schedule_info_window_layout = [
        [sg.Table(values=Schedule_List, headings=schedule_headings, max_col_width=35,
                  auto_size_columns=True,
                  display_row_numbers=False,
                  justification='Left',
                  num_rows=10,
                  enable_events=True,
                  enable_click_events=True,
                  key='-SCHEDULE_TABEL-',
                  row_height=35)]
    ]

    Schedule_info_window = sg.Window('Schedule Info', schedule_info_window_layout, modal=True)

    while True:
        event, values = Schedule_info_window.read()
        if event in (sg.WINDOW_CLOSED, 'Exit'):
            break
        if event == '-SCHEDULE_TABEL-':
            print(values['-SCHEDULE_TABEL-'][0])
            #name = Schedule_List[(values['-SCHEDULE_TABEL-'][0])][4],
            #print(type(Schedule_List[0][3]))
            #print(Schedule_List)

Image of GUI and time format

Pephy
  • 11
  • 1
  • Use following piece of code: df['Date'] = pd.to_datetime(df['Due_Date']).dt.date. This creates a new column with your desired format. – sadegh arefizadeh Jul 24 '22 at 04:52
  • I don't have "df" defined, is this different module? I also am not sure where I would put this in my code. Since my "Schedule_list" is already built, would it go into the "sg.Table" and layout section, so it would replace it before it builds the GUI? No it doesn't Rene, that seems to be when it imports the values of the date as a float. I have the date format importing, but its coming in as a "Timestamp" and giving me hours, minutes and seconds after the date, all set to zeros. – Pephy Jul 24 '22 at 05:04
  • `df` is the variable used by default for 99% of people using pandas to make a DataFrame, and it the example used in most documentation. You'll replace it with whatever you call yours. – BeRT2me Jul 24 '22 at 05:20
  • I'd suggest looking up and going through a `pandas` tutorial before trying to implement it into a whole new program. – BeRT2me Jul 24 '22 at 05:22

0 Answers0