[英]How to convert an Iterator into Pandas DataFrame?
I was trying to extract checkbox values from a PDF which I am able to with the help of the code below which I found from a thread in stackoverflow and it was provided by @Fabian.我试图从 PDF 中提取复选框值,我可以在下面的代码的帮助下从 stackoverflow 中的一个线程中找到它,它是由@Fabian 提供的。
Python: PDF: How to read from a form with radio buttons Python:PDF:如何使用单选按钮从表单中读取
filename = 'Accordd1.pdf'
fp = open(filename, 'rb')
parser = PDFParser(fp)
doc = PDFDocument(parser)
fields = resolve1(doc.catalog['AcroForm'])['Fields']
for i in fields:
field = resolve1(i)
name = str(field.get('T'),'utf-8')
value = field.get('V')
if value != None:
value = str(value)
if value[0] == r"/":
value = value[2:-1]
value = str(value)
print (f'{name}: {value}')
Below is the output I am getting:下面是我得到的 output:
Check Box47: None
Check Box48: None
Check Box49: None
Check Box50: None
Check Box51: None
Check Box52: None
Check Box53: None
Check Box54: None
Check Box55: None
Text56: None
I am very new to Python programming and not able to convert this output to a DataFrame as I want to export it into Excel - I tried appending the data into a blank list but it's not giving me correct results. I am very new to Python programming and not able to convert this output to a DataFrame as I want to export it into Excel - I tried appending the data into a blank list but it's not giving me correct results. Any help would be much appreciated.
任何帮助将非常感激。
Thank you so much in advance!非常感谢您!
IIUC:国际大学联盟:
import pandas as pd
data = []
for i in fields:
#Rest of logic
print (f'{name}: {value}')
data.append([name, value])
df = pd.DataFrame(data, columns=['name', 'value'])
df.to_excel("output.xlsx", index=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.