Xml to Csv Python Code too long The code takes a very simple xml and converts it into a dataframe in csv file.

This is the Xml file

&lt;Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;Phones&gt;
    &lt;Date /&gt;
    &lt;Prog /&gt;
    &lt;Box /&gt;
    &lt;Feature /&gt;
    &lt;WIN&gt;MAFWDS&lt;/WIN&gt;
    &lt;Set&gt;234234&lt;/Set&gt;
    &lt;Pr&gt;23423&lt;/Pr&gt;
    &lt;Number&gt;afasfhrtv&lt;/Number&gt;
    &lt;Simple&gt;dfasd&lt;/Simple&gt;
    &lt;Nr /&gt;
    &lt;gt&gt;6070106091&lt;/gt&gt;
    &lt;Reno&gt;1233&lt;/Reno&gt;
    &lt;QW&gt;3234&lt;/QW&gt;
    &lt;ER /&gt;
    &lt;VR /&gt;
    &lt;Use /&gt;
    &lt;Dar&gt;sdfsd&lt;/Dar&gt;
    &lt;age /&gt;
    &lt;name1&gt;sdfsfdfs&lt;/name1&gt;
    &lt;Sys&gt;IVECO E.A.SY.&lt;/Sys&gt;
    &lt;aac&gt;2019-05-29&lt;/aac&gt;
    &lt;time&gt;02:00&lt;/time&gt;
    &lt;nuk name="This is some text" text_g="asadsdas" text_h="2"&gt;fsdfsfd3432fdf&lt;/nuk&gt;
  &lt;/Phones&gt;

&lt;/Data&gt;


This is my code.
It works, it just gets way too long when I want to include all the children of the father phones. 
Looking for some help on how to shorter the code but it performing the same purpose.

This is the code

import xml.etree.cElementTree as et
import pandas as pd

df = pd.DataFrame()

def getvalueofnode(node):
    """ return node text or None """
    return node.text if node is not None else None


def main():
    """ main """
    parsed_xml = et.parse("short.xml")
    dfcols = ['Date', 'Prog', 'Box', 'Feature', 'WIN']
    df_xml = pd.DataFrame(columns=dfcols)

    for node in parsed_xml.findall('Phones'):
        Date = node.find("Date")
        Prog = node.find('Prog')
        Box = node.find('Box')
        Feature = node.find('Feature')
        WIN = node.find('WIN')

        df = df_xml.append(
            pd.Series([getvalueofnode(Date), getvalueofnode(Prog), getvalueofnode(Box),
                       getvalueofnode(Feature), getvalueofnode(WIN)],  index=dfcols),
            ignore_index=True)


    df.to_csv("./export.csv")

main()


This is all the columns declared fro dfcols

dfcols = ['Date', 'Prog', 'Box', 'Feature', 'WIN',
          'Set', 'Pr', 'Number','Simple','Nr',
          'gt', 'Reno','QW', 'ER','VR', 'Use',
          'Dar','age','name1', 'Sys' 'aac',
          'time', 'nuk'] 


Additional 

The element nuk has multiple attributes so each attributes gets its own column
Example

nuk_name, nuk_text_g, nuk_text_h
Optimization and restructuring

Redundant and inefficient things
The getvalueofnode function is unneeded: text attribute of a node will be None or string value. All intermediate dataframes are also unnecessary.Avoid using pd.Dataframe.append method within any loop as it will create a copy of accumulated dataframe of each loop iteration.

Namings
Use a meaningful names for your functions and if __name__ == '__main__': guard.I would suggest phones_to_df function name.



Assuming that the goal is to convert all Phones tags child nodes into dataframe records - all you need is collect a dictionaries of child nodes as &lt;el.tag: el.text&gt; mappings at once (+ special case for nuk tag, see below).Note, that some Phones tags could have their children in different order. So a list of dictionaries provides a robust way to arrange columns to respective values.

See the concise optimized approach below:

import xml.etree.cElementTree as cET
import pandas as pd


def phones_to_df(fname):
    tree = cET.parse(fname)
    pd.DataFrame([{**{el.tag: el.text for el in list(phone)},
                   **{f'nuk_{k}': v for k, v in phone.find('nuk').items()}}
                  for phone in tree.iterfind('Phones')]).to_csv('export.csv', index=False)


if __name__ == '__main__':
    phones_to_df(fname="test.xml")




After generating the expected export.csv file the resulting sample dataframe may look as below (I've tested on xml file with 2 Phones tags):

print(pd.read_csv('export.csv').to_string())

   Date  Prog  Box  Feature     WIN     Set     Pr     Number Simple  Nr          gt  Reno    QW  ER  VR  Use    Dar  age     name1            Sys         aac   time             nuk           nuk_name nuk_text_g  nuk_text_h
0   NaN   NaN  NaN      NaN  MAFWDS  234234  23423  afasfhrtv  dfasd NaN  6070106091  1233  3234 NaN NaN  NaN  sdfsd  NaN  sdfsfdfs  IVECO E.A.SY.  2019-05-29  02:00  fsdfsfd3432fdf  This is some text   asadsdas           2
1   NaN   NaN  NaN      NaN    ABCD     123    456        aaa    bbb NaN        1111   222   333 NaN NaN  NaN    rrr  NaN      wwww  TIMES E.A.SY.  2019-12-29  03:00        text ...  This is some text   asadsdas           2