有人能告诉我为什么这个代码没有生成任何csv文件吗?
import tabula
import pandas as pd
import re
_all_ = ['PdfFileReader', 'tabula', 'read_pdf' 'os', 're', 'csv']
def getdata():
import PyPDF2
# open the pdf file
object = PyPDF2.PdfFileReader("C:/Users/Manav Trivedi/Downloads/1-800-FLOWERS.COM, Inc._Annual Report_2017_EN.pdf")
# get number of pages
NumPages = object.getNumPages()
for i in range(0, NumPages):
df1 = {'Total Assets': [], 'Total Liabilities': [], 'Current Assets': [], 'Current Liabilities': []}
df2 = {'Revenue': [], 'Net Income': [], 'Gross Profit': [], 'Net Profit': []}
tables = tabula.read_pdf("C:/Users/Manav Trivedi/Downloads/1-800-FLOWERS.COM, Inc._Annual Report_2017_EN.pdf", encoding='utf-8', pages="all")
for table in tables:
if re.search("Total Assets", str(table)) or re.search("Total Liabilities", str(table)) or re.search("Current Assets",str(table)) or re.search("Current Liabilities", str(table)):
strg = str(table)
strg = strg.split(',')
for j in (0,strg):
if(j=='Total Assets'):
df1[0].extend(j+1)
if(j=='Total Liabilities'):
df1[1].extend(j+1)
if(j=='Current Assets'):
df1[2].extend(j+1)
if(j=='Current Liabilities'):
df1[3].extend(j+1)
df1 = pd.DataFrame.from_dict(df1)
df1.to_csv('Balance-sheet.csv', encoding='utf-8')
if re.search("Revenue", str(table)) or re.search("Net Income", str(table)) or re.search("Gross Profit",str(table)) or re.search("Net Profit", str(table)):
strg = str(table)
strg = strg.split(',')
for j in (0,strg):
if(j=='Revenue'):
df2[0].extend(j+1)
if(j=='Net Income'):
df2[1].extend(j+1)
if(j=='Gross Profit'):
df2[2].extend(j+1)
if(j=='Net Profit'):
df2[3].extend(j+1)
df2 = pd.DataFrame.from_dict(df2)
df2.to_csv('Income-Statement.csv', encoding='utf-8')
if __name__ == '__main__':
getdata()
暂无答案!
目前还没有任何答案,快来回答吧!