Q:

Extract text from multiple PDFs and write to a single CSV

I want to loop through all the PDFs in a directory, extract the text from each one using PDFminer, and then write the output to a single CSV file.  I am able to extract the text from each PDF individually by passing it to the function defined here.  I am also able to get a list of all the PDF filenames in a given directory.  But when I try to put the two together and write the results to a single CSV, I get a CSV with headers but no data. 
Here is my code:
import os
pdf_files = [name for name in os.listdir("C:\\My\\Directory\\Path") if name.endswith(".pdf")] #get all files in directory    
pdf_files_path = ["C:\\My\\Directory\\Path\\" + pdf_files[i] for i in range(len(pdf_files))] #add directory path

import pandas as pd
df = pd. DataFrame(columns=['FileName','Text'])

for i in range(len(pdf_files)):
    scraped_text = convert_pdf_to_txt(pdf_files_path[i])
    df.append({ 'FileName': pdf_files[i], 'Text': scraped_text[i]},ignore_index=True)

df.to_csv('output.csv')

The variables have the following values: 
pdf_files: ['12280_2007_Article_9000.pdf', '12280_2007_Article_9001.pdf', '12280_2007_Article_9002.pdf', '12280_2007_Article_9003.pdf', '12280_2007_Article_9004.pdf', '12280_2007_Article_9005.pdf', '12280_2007_Article_9006.pdf', '12280_2007_Article_9007.pdf', '12280_2007_Article_9008.pdf', '12280_2007_Article_9009.pdf']

pdf_files_path: ['C:\\My\\Directory Path\\12280_2007_Article_9000.pdf', etc...]

Empty DataFrame
Columns: [FileName, Text]
Index: []

Update: based on a suggestion from @AMC I checked the contents of scraped_text in the loop.  For the Text column, it seems that I'm looping through the characters in the first PDF file, rather than looping through each file in the directly.  Also, the contents of the loop are not getting written to the dataframe or CSV. 
12280_2007_Article_9000.pdf E
12280_2007_Article_9001.pdf a
12280_2007_Article_9002.pdf s
12280_2007_Article_9003.pdf t
12280_2007_Article_9004.pdf  
12280_2007_Article_9005.pdf A
12280_2007_Article_9006.pdf s
12280_2007_Article_9007.pdf i
12280_2007_Article_9008.pdf a
12280_2007_Article_9009.pdf n

A:

I guess you don't need pandas for that.  You can make it simpler by using the standard library csv. 
Another thing that can be improved, if you are using Python 3.4+, is to replace os with pathlib. 
Here is an almost complete example:
import csv
from pathlib import Path

folder = Path('c:/My/Directory/Path')
csv_file = Path('c:/path/to/output.csv')

with csv_file.open('w', encoding='utf-8') as f:
    writer = csv.writer(f, csv. QUOTE_ALL)

    writer.writerow(['FileName', 'Text'])

    for pdf_file in folder.glob('*.pdf'):
        pdf_text = convert_pdf_to_txt(pdf_file).replace('\n', '|')
        writer.writerow([pdf_file.name, pdf_text]) 

Another thing to bear in mind is to be sure pdf_text will be a single line or else your csv file will be kind of broken.  One way to work around that is to pick an arbitrary character to use in place of the new line marks.  If you pick the pipe character, for example, than you can do something like this, prior to writer.writerow:
pdf_text.replace('\n', '|')

It is not meant to be a complete example but a starting point.  I hope it helps.