I'm using a for loop to work through an entire folder of pdfs, which are converted to csv files.
import tabula
import os
import pandas as pd
files_in_directory = os.listdir()
filtered_files = [file for file in files_in_directory if file.endswith(".pdf")]
print(range(len(filtered_files)))
for file in range(len(filtered_files)):
print(file-1)
print(range(len(filtered_files)))
print(file)
print(filtered_files[file-1])
df = tabula.read_pdf(filtered_files[file-1])
csv_name = filtered_files[file-1] + '.csv'
df[file-1].to_csv(csv_name, encoding='utf-8')
Here is my log:
Traceback (most recent call last):
File "/Users/braydenyates/Documents/Band PDFS/csv_converter.py", line 16, in <module>
df[file-1].to_csv(csv_name, encoding='utf-8')
IndexError: list index out of range
The code appears to run two of the sixty-three files in the folder, then ends due to this error. Thank you for your help!