PyQt: How to sort QTableView columns of a excel file(strings and numericals and datetype)

前端 未结 2 1339
悲&欢浪女
悲&欢浪女 2021-01-27 16:10

This is a follow up question to: PyQt: How to sort QTableView columns(strings and numericals)

Now I am planning to do the same sorting for the excel files

Here i

2条回答
  •  臣服心动
    2021-01-27 16:50

    As Ekhumoro suggests, sorting of Excel data is easiest done with Pandas. I have tried similar operations with openpyxl, but it's too limited. Pandas can save you many lines of code.

    A small example:

    from PyQt4 import QtGui , QtCore
    import pandas as pd
    import numpy as np
    import time
    import sys
    
    # open excel file
    sales = pd.read_excel ("Sales.xlsx" , parse_dates=['Data'] )
    # select columns
    purchase_patterns = sales [['Total','Date']]
    # choose date index
    purchase_patterns = purchase_patterns.set_index("Date")
    # regroup / resample by week and get subtotals by sum 
    resample = purchase_patterns.resample ('W' , how = sum)
    

    Here are some nice links:

    • http://pbpython.com/excel-pandas-comp.html
    • http://chrisalbon.com/python/pandas_indexing_selecting.html
    • http://chrisalbon.com/python/pandas_dropping_column_and_rows.html
    • http://chris.friedline.net/2015-12-15-rutgers/lessons/python2/02-index-slice-subset.html

提交回复
热议问题