0

I am new to programming and I have a question in pandas in python that maybe noob but couldn't find an answer online.

I wrote a code to extract data from pdf using python.

The problem is that pandas is right aligned, I mean the first column appears on the right, how can I modify it that the first column appear on the left as default ?

import collections
import re
import pandas as pd 

pdf = pdfplumber.open("1.pdf")
cost_page = pdf.pages[3]
​
text = cost_page.extract_text()
​
print(text)
all_pattern = re.compile(r'(\d{6}\-\d{4}) ([A-Z]\w*\D*) ([\w,]+[,]+\w+) (\w*)')
line_items = []
for line in text.split('\n'):
    line = all_pattern.search(line)
    if line: 
        Account_Code = line.group(1)
        Description = line.group(2)
        Actual_to_date = line.group(3)
        Estimate_to_complete = line.group(4)
        line_items.append(titles(Account_Code, Description, Actual_to_date, Estimate_to_complete))

Result image

SpencerPark
  • 2,585
  • 1
  • 12
  • 19

1 Answers1

0

If you Want to inverse order of columns, you can do like describe in How to change the order of DataFrame columns?

cols = [df.columns[-1]] + [col for col in df if col != df.columns[-1]]
df = df[cols]
Renaud
  • 2,030
  • 2
  • 6
  • 18