Excel cell values filled with 0
<p>The part of code shown below   </p>

<pre><code>import collections
import csv
import sys


with open("321.csv","r") as f:
    cr = csv.reader(f,delimiter=",")
    d=collections.defaultdict(lambda : list())
    header=next(cr)   # read title. Retrieve the next item from the iterator by calling its __next__() method.
    for r in cr:
        d[r[0]].append(r[1])   # fill dict


with open("sorted output.csv","w") as f:

    cr = csv.writer(f,sys.stdout, lineterminator='\n')

    od = collections.OrderedDict(sorted(d.items()))#sort items based on dictionary key value
    for k,v in od.items():  #The method items() returns a list of dict's (key, value) tuple pairs
        v = [ord(i) for i in v]  # convert letters into numbers

        cr.writerow(v)
</code></pre>

<p>Gives me this output:</p>

<p><a href="http://i.stack.imgur.com/N4OhQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/N4OhQ.png" alt="enter image description here"></a></p>

<p>I want to fill all empty cells in the region: (A1::X30) with 0s.(Each time the cells that should be filled with 0s are defined by the length of the largest row. e.g. if the largest row had elements up until column Y the empty cells that should be filled with 0s would be in the region (A1::Y30)) </p>

<p>Can you help?</p>

<p>I'm not quite sure if I understand your question correctly. Here is an attempt:</p>

<p>To create a xls file that has just 0's an alternative could be to use pandas and numpy as follows:</p>

<pre><code>import pandas as pd
import numpy as np
import io

number_of_rows = 30
number_of_columns = 24

# Create a dataframe of 0's in the dimension you define above
df = pd.DataFrame(np.array([np.zeros(number_of_columns) for i in range(number_of_rows)]))

# Give out as xls file
df.to_excel('output.xls', index=False)
</code></pre>

<p>If you want to have certain cells with non-zeros and the rest with zeros, you can easily overwrite (before df.to_excle) by using something like the following with a function of your choice:</p>

<pre><code>df.set_values(row,column,value)
</code></pre>

<p>Hope that helped a little bit.</p>

python excel