'convert excel data to text file particular blocks format using python

I am new to python related to data parsing or formatting. I have a use-case where I have excel sheet created by a tool, which consists of configuration data in rows and columns I would like to convert to normal text file in a particular blocks enclosed with {} like defining variable keys.

Here is a my Excel sheet: The input Excel sheet

Here is the code i converted my excel to text but it contained data with many NAN and relevant data as well.

import pandas as pd

df = pd.read_excel('enum_dns.xlsx', sheet_name='DNS-NG', engine='openpyxl')

with open('myfile.txt', 'w') as outfile:
    df.to_string(outfile)

Desired output:

 dns-local::udp-tcp v-xnmmsite1-e2-local {
      description="Edge-2 xnmm/Dns Traffic" 
      state="ENABLED" 
      address=[10.x.x.x] 
      port=53 
      udp-settings {
         thread-count=1 
         packet-size=512
      } 
      tcp-settings {
         backlog=50 
         read-timeout=180
      }
   }

   dns-peer::client ims-site-a {
      state="ENABLED" 
      context="xnmmdns-context" 
      binding=&v-xnmmsite1-e2-local 
      address::SUBNET=10.x.x.x/23 
      tcp-settings {
         maximum-connections=100 
         read-timeout=180
      }
   }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source