Pandas数据帧是从右向左的吗?

2024-03-28 20:58:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我是编程新手,我有一个关于python中pandas的问题,可能是noob,但在网上找不到答案

我编写了一段代码,使用python从pdf中提取数据

问题是熊猫是右对齐的,我的意思是第一列显示在右边,我如何修改它,使第一列默认显示在左边

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


Tags: totextimportrepandaspdflinepage