{"id":398,"date":"2023-06-21T23:47:26","date_gmt":"2023-06-21T23:47:26","guid":{"rendered":"https:\/\/www.jibsheet.net\/linux\/?p=398"},"modified":"2023-06-21T23:48:59","modified_gmt":"2023-06-21T23:48:59","slug":"bing-chat-use-a-class-as-a-template-prompt","status":"publish","type":"post","link":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/","title":{"rendered":"Bing Chat &#8211; use a class as a template prompt"},"content":{"rendered":"<p>Here is my now goto prompt for when I am working on a project &#8211; have a class that I need to mimic the interfaces.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">use the following class as a template.   Call the new class \"MainframeExcelText\"  The init take file and sheet and sets row and column location to 0.   1 function - write_text will take a row,col and string.  It will write the text to the location in the excel spreadsheet using openpyxl.  a close function will close he sheet\r\n\r\nclass MainframeExcelPivot:\r\n\r\n    # Define the init method\r\n    def __init__(self, excel_file, sheet_name):\r\n        # Load the Excel file into a DataFrame\r\n        self.df = pd.read_excel(excel_file, sheet_name=sheet_name)\r\n        # Store the Excel file name and sheet name as attributes\r\n        self.excel_file = excel_file\r\n        self.sheet_name = sheet_name\r\n        self.start_row = 1\r\n        self.start_col = 1\r\n        self.book = load_workbook(self.excel_file)\r\n        # Create an Excel writer object with openpyxl engine and append mode\r\n        self.writer = pd.ExcelWriter(self.excel_file, engine=\"openpyxl\", mode=\"a\", if_sheet_exists=\"overlay\")\r\n        # Assign the book attribute to the loaded workbook\r\n        self.writer.book = self.book\r\n\r\n    def set_loc(self, start_row, start_col ):\r\n        self.start_row = start_row\r\n        self.start_col = start_col\r\n\r\n    # Define the create_manager_pivot method\r\n    def create_manager_pivot(self, sheet_name):\r\n        # Create a pivot table with index \"Manager\" and values \"Case\" with count function\r\n        self.df[\"Aged_Backlog\"] = self.df[\"Aged\"].str.contains(\"&gt;21\")\r\n        self.table = pd.pivot_table(self.df, index=\"Manager\", values=[\"Case\", \"Aged_Backlog\"],\r\n                                    aggfunc={\"Case\": \"count\",\r\n                                             \"Aged_Backlog\": np.sum},\r\n                                    margins=True, margins_name=\"Total\")\r\n\r\n        self.table[\"Percent_Aged\"] = self.table[\"Aged_Backlog\"].div(\r\n            self.table[\"Case\"]).mul(100).round(2)\r\n        # Save the pivot table as a new sheet in the Excel file\r\n\r\n    def sheet_filter_with_compare(self, sheet_name, index_col, value_col, aggfunc=np.sum, filter_col=None, filter_values=None):\r\n    # Create a pivot table with the given parameters and a filter on filter_col column\r\n        if filter_col and filter_values:\r\n           my_pd = self.df.query(f\"{filter_col} in {filter_values}\")\r\n           # Construct the query string using the filter parameters\r\n           query_str = f\"{filter_col} in {filter_values}\"\r\n           self.table = pd.pivot_table(my_pd, index=index_col, values=value_col,\r\n                                       aggfunc=aggfunc,\r\n                                       margins=True, margins_name=\"Total\")\r\n        else:\r\n           # No filter applied\r\n           self.table = pd.pivot_table(self.df, index=index_col, values=value_col,\r\n                                       aggfunc=aggfunc,\r\n                                       margins=True, margins_name=\"Total\")\r\n             # Save the pivot table as a new sheet in the Excel file\r\n        self.save_table(sheet_name)\r\n\r\n    # Define the save method\r\n\r\n    def save_table(self, sheet_name):\r\n        self.table.to_excel(self.writer, sheet_name=sheet_name, startrow = self.start_row, startcol=self.start_col )\r\n    def save(self, sheet_name):\r\n        # Save the file\r\n        self.writer.save()<\/pre>\n<p>Here is what it generated.<\/p>\n<p>&nbsp;<\/p>\n<p>&#8220;I\u2019ll try to help you with that. Here is a possible class that meets your requirements:&#8221;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Import openpyxl module\r\nimport openpyxl\r\n\r\n# Define the MainframeExcelText class\r\nclass MainframeExcelText:\r\n\r\n    # Define the init method\r\n    def __init__(self, file, sheet):\r\n        # Load the workbook and the sheet\r\n        self.wb = openpyxl.load_workbook(file)\r\n        self.ws = self.wb[sheet]\r\n        # Store the file and sheet names as attributes\r\n        self.file = file\r\n        self.sheet = sheet\r\n        # Set the row and column location to 0\r\n        self.row = 0\r\n        self.col = 0\r\n\r\n    # Define the write_text method\r\n    def write_text(self, row, col, string):\r\n        # Write the string to the given row and column location in the sheet\r\n        self.ws.cell(row=row, column=col).value = string\r\n\r\n    # Define the close method\r\n    def close(self):\r\n        # Save and close the workbook\r\n        self.wb.save(self.file)\r\n        self.wb.close()\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is my now goto prompt for when I am working on a project &#8211; have a class that I need to mimic the interfaces. use the following class as a template. Call the new class &#8220;MainframeExcelText&#8221; The init take file and sheet and sets row and column location to 0. 1 function &#8211; write_text will take a row,col and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[32,30,14,7],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Bing Chat - use a class as a template prompt - Jon Allen&#039;s Linux Stuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bing Chat - use a class as a template prompt - Jon Allen&#039;s Linux Stuff\" \/>\n<meta property=\"og:description\" content=\"Here is my now goto prompt for when I am working on a project &#8211; have a class that I need to mimic the interfaces. use the following class as a template. Call the new class &quot;MainframeExcelText&quot; The init take file and sheet and sets row and column location to 0. 1 function - write_text will take a row,col and [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/\" \/>\n<meta property=\"og:site_name\" content=\"Jon Allen&#039;s Linux Stuff\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-21T23:47:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-21T23:48:59+00:00\" \/>\n<meta name=\"author\" content=\"jonallen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"jonallen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/\"},\"author\":{\"name\":\"jonallen\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\"},\"headline\":\"Bing Chat &#8211; use a class as a template prompt\",\"datePublished\":\"2023-06-21T23:47:26+00:00\",\"dateModified\":\"2023-06-21T23:48:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/\"},\"wordCount\":62,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\"},\"articleSection\":[\"Bing Chat\",\"ChatGPT\",\"Pandas\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/\",\"url\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/\",\"name\":\"Bing Chat - use a class as a template prompt - Jon Allen&#039;s Linux Stuff\",\"isPartOf\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#website\"},\"datePublished\":\"2023-06-21T23:47:26+00:00\",\"dateModified\":\"2023-06-21T23:48:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.jibsheet.net\/linux\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bing Chat &#8211; use a class as a template prompt\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#website\",\"url\":\"https:\/\/www.jibsheet.net\/linux\/\",\"name\":\"Jon Allen's Linux Stuff\",\"description\":\"Howto&#039;s, Observations, and stuff\",\"publisher\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.jibsheet.net\/linux\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\",\"name\":\"jonallen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g\",\"caption\":\"jonallen\"},\"logo\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/www.jibsheet.net\/linux\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bing Chat - use a class as a template prompt - Jon Allen&#039;s Linux Stuff","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/","og_locale":"en_US","og_type":"article","og_title":"Bing Chat - use a class as a template prompt - Jon Allen&#039;s Linux Stuff","og_description":"Here is my now goto prompt for when I am working on a project &#8211; have a class that I need to mimic the interfaces. use the following class as a template. Call the new class \"MainframeExcelText\" The init take file and sheet and sets row and column location to 0. 1 function - write_text will take a row,col and [&hellip;]","og_url":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/","og_site_name":"Jon Allen&#039;s Linux Stuff","article_published_time":"2023-06-21T23:47:26+00:00","article_modified_time":"2023-06-21T23:48:59+00:00","author":"jonallen","twitter_card":"summary_large_image","twitter_misc":{"Written by":"jonallen","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/#article","isPartOf":{"@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/"},"author":{"name":"jonallen","@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993"},"headline":"Bing Chat &#8211; use a class as a template prompt","datePublished":"2023-06-21T23:47:26+00:00","dateModified":"2023-06-21T23:48:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/"},"wordCount":62,"commentCount":0,"publisher":{"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993"},"articleSection":["Bing Chat","ChatGPT","Pandas","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/","url":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/","name":"Bing Chat - use a class as a template prompt - Jon Allen&#039;s Linux Stuff","isPartOf":{"@id":"https:\/\/www.jibsheet.net\/linux\/#website"},"datePublished":"2023-06-21T23:47:26+00:00","dateModified":"2023-06-21T23:48:59+00:00","breadcrumb":{"@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2023\/06\/21\/bing-chat-use-a-class-as-a-template-prompt\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.jibsheet.net\/linux\/"},{"@type":"ListItem","position":2,"name":"Bing Chat &#8211; use a class as a template prompt"}]},{"@type":"WebSite","@id":"https:\/\/www.jibsheet.net\/linux\/#website","url":"https:\/\/www.jibsheet.net\/linux\/","name":"Jon Allen's Linux Stuff","description":"Howto&#039;s, Observations, and stuff","publisher":{"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.jibsheet.net\/linux\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993","name":"jonallen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g","caption":"jonallen"},"logo":{"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.jibsheet.net\/linux"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts\/398"}],"collection":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":2,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":400,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts\/398\/revisions\/400"}],"wp:attachment":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}