熊猫数据框是从右到左?

时间:2020-04-12 20:13:31

标签: python pandas dataframe alignment

我是编程新手,我在python的熊猫中有一个问题,可能是菜鸟,但找不到在线答案。

我编写了一个代码,使用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))

And routing is:

1 个答案:

答案 0 :(得分:0)

如果要反转列的顺序,可以像在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]