I am attempting to create a new line wherever either charactor \n or \r appears in my output.
For example the following code:
document_analysis_client = DocumentAnalysisClient(
endpoint=endpoint, credential=AzureKeyCredential(key)
)
for blob in container.list_blobs():
blob_url = container_url + "/" + blob.name
poller = document_analysis_client.begin_analyze_document_from_url(
"prebuilt-read", blob_url)
result = poller.result()
print("Scanning " + blob.name + "...")
print ("document contains", result.content)
Produces the following print
Scanning rawpdfs/multipage_invoice1.pdf...
document contains Company A Invoice
Invoice For:
Address:
567 Main St.
Redmond, WA
555-555-5555
Bilbo Baggins
123 Hobbit Lane
Redmond, WA
555-555-5555
Subtotal: 300.00
Tax: 30.00
Tip: 100.00
Total: 430.00
Signature: ____Bilbo Baggins__________
Item
Quantity
Price
A
1
10.99
B
2
14.67
C
4
15.66
D
1
12.00
However when I execute the method result.content produces the following output.
Out[47]: 'Company A Invoice\nInvoice For:\nAddress:\n567 Main St.\nRedmond, WA\n555-555-5555\nBilbo Baggins\n123 Hobbit Lane\nRedmond, WA\n555-555-5555\nSubtotal: 300.00\nTax: 30.00\nTip: 100.00\nTotal: 430.00\nSignature: ____Bilbo Baggins__________\nItem\nQuantity\nPrice\nA\n1\n10.99\nB\n2\n14.67\nC\n4\n15.66\nD\n1\n12.00\nE\n4\n10.00\nF\n6\n12.00\nG\n8\n22.00'
As you can see the whole document is on a single line. Therefore, I believe I need to figure out how to establish multi-line by removing the \n with a carriage return?
I tried it with Pandas as follows:
mydf = result.content
pandas_df = pd.read_csv("mydf")
pandas_df = pandas_df.replace({r'\\r': ''}, regex=True)
pandas_df = pandas_df.replace({r'\\n': ''}, regex=True)
But it failed. I think my attempt is way off track.
Any thoughts?
Ultimately, once I have a solution to the question I will be converting the pandas dataframe to Spark dataframe
EDIT
I have done some digging around and I think I will need to convert mydf into a pandas dataframe do something like the following:
mydf.to_csv('/dbfs/mnt/....../df.csv', sep=',', header=True, index=False)
However, I'm not sure how to convert "mydf" to pandas?