python - 在将数据从 pdfplumber 导入到 .csv 文件时需要帮助
问题描述
我使用 pdfplumber 从 pdf 中提取文本,但是当我尝试使用 to_csv 导入数据时抛出 #me 错误。在将数据导入 .csv 时需要帮助
import pdfplumber
import pandas as pd
import numpy as np
import os
import re
from collections import OrderedDict
pdf = pdfplumber.open('C:/Users/Desktop/Mydata.pdf')
page = pdf.pages[1-76]
text = page.extract_text()
text
print(text)
text2 = pd.DataFrame([text])
text2.to_csv("C:\\Users\\Desktop\\MyPDFData\\converted_text.csv")
没有得到导入文件中的数据只是得到了一个空文件
解决方案
你可能不需要熊猫来做这件事。只需先打开 CSV 引擎:
with open(your_csv_file_name, mode='w', newline='') as export_csv:
csv_writer = csv.writer(export_csv, escapechar=' ', quoting=csv.QUOTE_NONE)
csv_writer.writerow(text)
有一个很好的页面来了解 CSV 导出:
推荐阅读
- javascript - 如何在边框半径元素中隐藏滚动条拇指
- flutter - 如何在没有上下文的情况下导航?
- java - 未应用 Apache POI Java XSSFCell 数据格式
- azure - 如何获取 Azure 存储加密状态
- javascript - React Native 获取错误:“[未处理的承诺拒绝:TypeError:网络请求失败]”
- html - 缩小浏览器时文本超出页脚
- sql - SQL Server 2008 的期初和期末数量有问题?
- c# - 使用 C# 库观看 Kubernetes 事件
- typescript - Nexus GraqphQL 服务器未重新启动
- ios - 配置文件在临时分发中未能通过资格认证?