How to create 2 csv files when using recursion
<p>I want to create 2 csv files.</p>

<p>I have 2 array in one function then i am looping through it and calling another function to write into an csv file so it will create 2 csv files</p>

<pre><code>import time
import datetime
import csv
time_value = time.time()
def csv_write(s):
    print s
    f3 = open("import_"+str(int(time_value))+".csv", 'wt')
    writer = csv.writer(f3,delimiter = ',', lineterminator='\n',quoting=csv.QUOTE_ALL)
    writer.writerow(s)
    f3.close()

def process_array():
    a = [["a","b"],["s","v"]]
    for s in a:
        csv_write(s)

process_array()
</code></pre>

<p>The whole idea is to create 2 csv files since it has 2 array elements but the above code just overwrites the files and the codes creates only one csv file at end</p>

<p>So if the array has 10 elements then the code should create 10 csv files</p>

<p>How to do it?</p>

<p>First convert it into Dataframe then save it in CSV format </p>

<pre><code>import pandas as pd

a = [["a","b"],["s","v"]]

df=pd.DataFrame(a)

i=len(df)

for j in range(i):
    df.iloc[:,j].to_csv(str(j)+'.csv',index=False)
</code></pre>

<p>After executing this code, you will get two csv files (As length of array is two) </p>

python arrays csv