Create csv file in python
<p>I created one program in python in which I used collaborative filtering to find Item based CF.
    My code is,</p>

<pre><code># Create a placeholder items for closes neighbours to an item
data_neighbours = pd.DataFrame(index=data_ibs.columns,columns=[range(1,13)])
print data_neighbours
# Loop through our similarity dataframe and fill in neighbouring item names
for i in range(0,len(data_ibs.columns)):
    ##use sort_values(...)
    data_neighbours.ix[i,:10] = data_ibs.ix[0:,i].sort_values(ascending=[1, 0])[:10].index
    data_neighbours.ix[i,:10] = data_ibs.ix[0:,i].sort_values(ascending=[1, 0])[:10].index



print data_neighbours.ix[i,:10]

Output is in table:


         user         1          2          3
    0   192.   c1s1b1p3   c1s1b1p4   c1s1b1p5
    1   192.   c1s1b1p3   c1s1b1p4   c1s1b1p5
    2   192.   c1s1b1p3   c1s1b1p4   c1s1b1p5
    3   192.   c1s1b1p3   c1s1b1p4   c1s1b1p5
    4   192.   c1s1b1p7   c1s1b1p8  c1s1b1p10
    5   192    c1s1b1p5   c1s1b1p6   c1s1b1p7
    6   192.   c1s1b1p3   c1s1b1p4   c1s1b1p5
    7   192.   c1s1b1p8   c1s1b1p9   c1s1b1p4
    8   192.   c1s1b1p6  c1s1b1p10   c1s1b1p5
    9   192.   c1s1b1p3   c1s1b1p5   c1s1b1p7
    10  192.   c1s1b1p6   c1s1b1p8   c1s1b1p9
</code></pre>

<p>This is table display on cmd prompt I want to save this table in csv file. How I can create csv file to store this table.</p>

<pre><code>with open('hi.csv','wb') as ff:
    sw=csv.writer(ff,delimiter=',',quoting=csv.QUOTE_MINIMAL) 
       for rows in data_neighbours: 
           sw.writerow(rows)
</code></pre>

<p>data_neighbours must contain lists in row wise....</p>

python