最近发现excel数据量极大,并且通过简单的数据操作不能提取到我需要的数据,如果单独操作,数据量太大耗时太长。
想着通过简单的方式,并且快速提取数据,就想到了Python。
python操作Excel使用的openyxl和pandas对Excel进行操作。
代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020-02-24 下午 03:43
# @Author : Zhanxing
# @Site :
# @File : 提取字段.py
# @Software: PyCharm
import openpyxl
import pandas as pd
from xlutils.copy import copy
df=pd.read_excel('222.xlsx',sheet_name='XXX')
data=(df[['XXX','XXX']])
data.to_excel("new.xlsx", index=False)
class Excel:
def __init__(self, excel_file):
self.excel = openpyxl.load_workbook(excel_file)
self.sheet_name = self.excel.get_sheet_names()
self.sheet = self.excel.get_sheet_by_name(self.sh