
网上搞了个代码,读取pdf中数据导出到txt中,但是导出结果中包含“NaN"和“/",想要将“NaN"和”/“替换成空格。求各位大神怎么操作。
# 事先安装好tabula,pandas:
import pandas as pd
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)
import tabula
import sys
# 指定文件名;文件位置
file = "活页夹1.pdf"
path = 'C:/Users/邢燕飞/Desktop/' + file
#读取表格
df = tabula.read_pdf(path, pages = 'all', multiple_tables = True)
stdout=print(df)
with open('C:/Users/邢燕飞/Desktop/xxx.txt', 'w') as f:
print(df, file=f)