I am a newbee just started my first language as Python.
I am trying to write code to open multiple encrypted pdf files and save them without password.
All files are in a folder, I have a csv file filePassword.csv
with columns filename
and password
.
But my code is not working. Please guide me on how to solve this error.
import pikepdf as pdf
import pandas as pd
df = pd.read_csv('filePassword.csv')
filename, password = df['filename'], df['password']
for file in filename:
for code in password:
file1 = pdf.open(file,code)
file1.save('1_'+filename)
I get this error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
You can loop over the dataframe df
using iterrows()
and then access filename
and password
in following way. There is no need of nested loops.
import pikepdf as pdf
import pandas as pd
df = pd.read_csv('filePassword.csv')
for index, row in df.iterrows():
file1 = pdf.open(row['filename'], row['password'])
file1.save('1_'+row['filename'])