Copy number of rows for n number of times using Python and write them in other file
<p>Hi I'm writing a simple script to copy a set of rows from a <strong>csv</strong> file and paste them for N number of times in other file. </p>

<p>I'm not able to write the result into other file.</p>

<p>Please find the code below:</p>

<pre><code>import csv
for i in range(2):
    with open('C:\\Python\\CopyPaste\\result2.csv', 'r') as fp:
        data = fp.readlines()
    fp.close()

with open('C:\\Python\\CopyPaste\\mydata.csv', 'w') as mycsvfile:
    thedatawriter = csv.writer(mycsvfile)
    for row in data:
        thedatawriter.writerow(row)
</code></pre>

<p><img src="http://i.stack.imgur.com/ssulP.jpg" alt="enter image description here"></p>

<p>I guess your question is : read a .csv file and then write the data to another .csv file for N times?</p>

<p>If my recognition is right, my suggestion would be using pandas library, that's very convenient.</p>

<p>Something like:</p>

<pre><code>import pandas as pd

df = pd.read_csv('origin.csv')
df.to_csv('output.csv')
</code></pre>

python csv