So, I am trying to convert multiple PDFs into CSV. I have a code that does the scanning and transforms everything into a single CSV as of now. However, instead of converting the data into one single CSV, I want Python to save individual CSVs for each PDF processed (this is primarily to identify a new file as there is more code on top of this that formats the data). I have the below code now, but I can't find a way to save multiple files. Any assistance will be appreciated.
import os
import pdfplumber
import pandas as pd
directory = r'Folfer Path'
lines = []
for filename in os.listdir(directory):
if filename.endswith(".pdf"):
pdf = os.path.join(directory, filename)
with pdfplumber.open(pdf) as pdf:
pages = pdf.pages
for page in pdf.pages:
text = page.extract_text()
for line in text.split('\n'):
lines.append(line)
print(line)
df = pd.DataFrame(lines)
df.to_csv('Folder Path/ filename.csv')