python xlsxwriter write cell according to row data
<p>I have python dictionaries: </p>

<pre><code>student_age = {'bala':20,'raju':21}
student_id = {'bala':289,'raju':567} 
</code></pre>

<p>and ten more similar dictionaries with key as student name and value different field.</p>

<p><strong>Expected excel result:</strong>
<a href="https://i.stack.imgur.com/moL7u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/moL7u.png" alt="enter image description here"></a></p>

<p>Instead of </p>

<pre><code>worksheet.write(0,2,20)
</code></pre>

<p>I want to write according to student names like <em>write("bala"-> "age" ,20)</em></p>

<p><strong>Updated code:</strong></p>

<pre><code>import xlsxwriter
workbook = xlsxwriter.Workbook('student_data.xlsx')
worksheet = workbook.add_worksheet()

student_age={'bala':20,'raju':21,'ram':22}
student_id={'bala':289,'ram':567,'raju':654}
students = student_id.keys()
print(len(student_age.keys()))
fields = [student_age, student_id] # add other dicts here...

for row, student in enumerate(students):
    worksheet.write(row, 0, student) # name column
    for col, student_data in enumerate(fields):
        col = col + 1
        worksheet.write(row, col, student_data[student])
workbook.close()
</code></pre>

<p>The above code is working fine but with following disputes:</p>

<ol>
<li>The output starts from row 0,column 0 but I want the headings on row 1 and need the output from row 1

<ol start="2">
<li>If student_id keys is 20 and i have one dictionary with just 15 students , how to leave blank for those items without getting error and traverse it?</li>
</ol></li>
</ol>