If it keeps on straining …

… concrete’s goin’ to break:

To find out what this has to do with predicting concrete deflections, book into the Concrete Institute seminar on “Finite Element Analysis of Concrete Structures”:

Finite Element Analysis of Concrete Structures – Software and Practice

When:
Wednesday, 18 May 2016
4:45 PM – 8:00 PM

Where:
Ryde-Eastwood Leagues Club
117 Ryedale Road , West Ryde NSW 2114

Posted in Bach, Beam Bending, Concrete, Newton | Tagged , , , | Leave a comment

Beetles …

… from the collections of the Oxford University Museum of Natural History, portraits by Levon Biss:

Beetles1
Beetles2 beetles3 Beetles4 Beetles5

More at:

Microsculpture

Posted in Bach, Newton | Tagged , | Leave a comment

xlwSciPy 1.7

Following recent posts on xlwings 0.7.1, dictionaries, and optional arguments and xlwings – dataframes and statistics, I have added the associated functions and examples to the xlwSciPy spreadsheet, and also updated it to xlwings 0.71.

The new spreadsheet can be downloaded from:

xlScipy-xlw.zip

including full open source code.

The spreadsheet requires Python, including xlwings, Numpy, Scipy and Pandas (all of which are free, and included in the Anaconda package).

Posted in Excel, Link to Python, Maths, Newton, NumPy and SciPy, Python Pandas, UDFs, VBA | Tagged , , , , , , , , | 4 Comments

Jack Bruce on double bass

Read all about it: Things We Like

Posted in Bach | Tagged , , | 1 Comment

xlwings – dataframes and statistics

Another data conversion option offered by the latest xlwings release is Pandas dataframes and dataseries.  This post will look at how to pass an Excel range as a dataframe or dataseries in a User Defined Function (UDF), and some simple statistical applications, but this is barely scratching the surface of the potential of the Pandas Python Data Analysis Library.

To use the Pandas data structures, import pandas and xlwings; the data type can then be defined with an xw.arg decorator:

import pandas as pd
import xlwings as xw 

@xw.arg('datrange', pd.DataFrame, index = 0, header = 0)    
def rtnpdframe(datrange):
    return datrange
    
@xw.arg('datrange', pd.Series, header = 0)    
def rtnpdseries(datrange):
    return datrange

The Python functions can then be called from VBA:

Function GetDFrame(DRange As Variant)
On Error GoTo rtnerr:
    GetDFrame = Py.CallUDF(ModName, "rtnpdframe", Array(DRange), ThisWorkbook)
    Exit Function
rtnerr:
    GetDFrame = Err.Description
End Function

Function GetDSeries(DRange As Variant)
On Error GoTo rtnerr:
    GetDSeries = Py.CallUDF(ModName, "rtnpdseries", Array(DRange), ThisWorkbook)
    Exit Function
rtnerr:
    GetDSeries = Err.Description
End Function

Use of these functions is shown in the screenshots below:

DFrame1-1

The xl_Corr UDF shown above is taken from the xlwings documentation:

@xw.func
@xw.arg('x', pd.DataFrame, index=False, header=False)
@xw.ret(index=False, header=False)    
def xl_Correl(x):
    return x.corr()

I have added a simple extension to allow an Excel UDF to call any of the dataframe methods:

@xw.func
@xw.arg('x', pd.DataFrame, index=False, header=False)
@xw.ret(index=False, header=False)    
def xl_Stats(x, stat):
    method = getattr(x, stat)
    return method()

Use of this UDF with four different statistics functions is shown below.  In these examples the statistic is a single value, and the results for each of the three columns of the input range are returned as a single column with three rows.

DFrame1-2

The “describe” method returns 8 values for each column in the input range:

DFrame1-3

The Pandas documentation lists 20 common statistics functions available as dataframe methods.  The screenshot below shows the use of the xl_Stats UDF, in conjunction with the Index function to call any of these 20 functions.  In the example shown the cumsum function returns one row for each row of the input data (only the first three are shown):

DFrame1-4

The functions shown above have been added to:
xlwDict.zip
available for free download, with full open source code.

 

Posted in Excel, Link to Python, Maths, Newton, Python Pandas, UDFs, VBA | Tagged , , , , , , , | 4 Comments