title: Writing pandas df to xml file (Python 3.x)
body: <p>I have the following pandas df:</p>
  
  <pre><code>userid | fid | response
  -----------------------
  1125 | 58940 | xml1
  3344 | 47839 | xml2
  3455 | 12335 | xml3
  </code></pre>
  
  <p>I want to iterate this df row by row and insert each row into a file. Then convert the xml into json to store in mongodb. The xml is a large xml document.</p>
  
  <p>The final result I want it like json like:</p>
  
  <pre><code>"userid" : "1125",
  "fid" : "5890",
  "response" : "xml1"
  </code></pre>
  
  <p>The xml1 is a big hierarchy.</p>
  
  <p>So far, my code looks like this but I am going nowhere with it:</p>
  
  <pre><code>import pandas as pd
  raw_data = pd.read_csv('C:\\Users\\Desktop\\xml.csv', sep = '|') 
  df = pd.DataFrame(raw_data, columns = ['userid', 'fid', 'response'])
  
  file = 'file{}.xml'
      for row in df.iterrows():
          with open(file.xml, 'w') as f:
              f.write(row)
  </code></pre>
  
  <p>I want to use only one file rather than separate file for each row as there are more than 2 million records. Every row will be inserted into a document and after conversion it will clear the content before writing the next row.</p>
  
  <p>Basically I need to write to a file just to convert it into json.</p>
  
  <p>I hope the question is clear.          </p>