[英]pandas dataframe is from the right to the left?
我是编程新手,我在 python 的 pandas 中有一个问题,可能是菜鸟,但无法在线找到答案。
我编写了一个代码,使用 python 从 pdf 中提取数据。
问题是 pandas 是右对齐的,我的意思是第一列出现在右边,我该如何修改第一列默认出现在左边?
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))
如果您想反转列的顺序,您可以像如何更改 DataFrame 列的顺序?
cols = [df.columns[-1]] + [col for col in df if col != df.columns[-1]]
df = df[cols]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.