How save an string output after a for loop in python with pandas and csv modules?
<p>I have the following for loop:</p>

<pre><code>    for titles in titles:
        title = titles.xpath("a/text()").extract()
        link = titles.xpath("a/@href").extract()
        print(title, link)
</code></pre>

<p>How can I dump the title and link into a formmated .csv file?</p>

<p>Use a <a href="https://docs.python.org/2/library/csv.html" rel="nofollow">csv writer</a>.</p>

<p>Basic usage:</p>

<pre><code>import csv
with open('file.csv') as f:
    writer = csv.writer(f)
    writer.writerow(["title", "link"])
</code></pre>

python python-3.x csv pandas