[Tutor] creating a connection class

2018-03-30 Thread Glenn Schultz

All,

I can create a connection as follows and it works but I think it is best to 
have a connection class that opens and closes.  I create the connection class 
as outline below.  However, it does not work - meaning that it does not return 
a connection rather it returns 
<__main__.modelingdb at 0x40dfbb0>

Any help getting the connection class to work is greatly appreciated.

Glenn

model_prod_conn = pyodbc.connect(
driver = '{ODBC Driver 13 for SQL Server}',
server = 'foo',
database = 'foo',
username = 'foo',
password = 'foo',
trusted_connection = 'yes')


class modelingdb(object):
  def __init__(self):
   self._db_connection = pyodbc.connect(
   driver = '{ODBC Driver 13 for SQL Server}',
   server = 'foo',
   database = 'foo',
   username = 'foo',
   password = 'foo',
   trusted_connection = 'yes')
   self._db_cur = self._db_connection.cursor()

def __del__(self):
self._db_connection.close()


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] pandas read sql query advice

2018-04-27 Thread Glenn Schultz

All,

I have the following set-up (below) which will be used to call data from 
multiple sectors.  There is a sql query (transact sql) and connection.  This 
works fine.  However, I would like to parametrize the query so I can enter 
different sectors.  I have checked through pyodbc and several SO posts.  
However, I am stuck and cannot get the parametrized version to work.  Most 
examples I have found are either sqlite or postgres.

sql ="""select foo from mutable where model sector = 'mysector'"""
conn = myconn

def modeldata(modelquery, conn)
modeldata = pandas.read_sql_query(sql, conn)
return modeldata

Here is what I have tried (various combinations) - what am I doing wrong?

sql ="""select foo from mutable where model sector = ?""", [params]
conn = myconn

def modeldata(modelquery, conn, params)
modeldata = pandas.read_sql_query(sql, conn, params)
return modeldata

Thanks in advance,
Glenn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] PMML vs. Pickel

2018-05-07 Thread Glenn Schultz

All, have a Python prepayment model that must be integrated into 3rd party 
vendor software considering translating to PMML.  I have been researching this. 
 Any potential downside?
Glenn
Sent from my iPhone

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] help with Pandas

2018-05-22 Thread Glenn Schultz

All,

I have a dataframe with the column 'loanage' and a function to transform 
loanage, which will be part of a pipline, I am trying to apply the function to 
the data frame as follows:

df['loanage'].apply(myfunction(x = 2, y = 10, z = 10, df['loanage]), axis = 0)

I get value error: The truth in the series is ambigous.

However, if I write a for loop indexing into the dataframe the function works.  
I am of the understanding based on the docs and online research I should be 
able to do the above.  I cannot figure out what I am doing wrong and have tried 
every possible combination I have seen in the docs and online.  Any help is 
appreciated.

Glenn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] adding numpy to pandas

2018-06-20 Thread Glenn Schultz

All,

I have a pandas dataframe and a predict result (numpy array) of a classifier 
[[0,1],[1,0]].  What I would like to do is as the positive to the pandas 
dataframe.  I use predict[:,1] to slice the postive from numpy which gives me a 
row of the result.  but I cannot concat to the pandas df['result'] = 
predict[:,1] does not work and I have tried various ways to do this with no 
result.  I am missing something here.  Any help is appreciated.

Glenn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Building a Package

2018-08-21 Thread Glenn Schultz via Tutor

All,
I have a project pthon(3.7) I have followed the python setup instructions. I 
get a dist folder with the correct files.  Now, I would like to install locally 
from my local machine (note I am not using virtual enviroment as our firewall 
does not allow installation of packages when using VE).  In my site packages 
directory I get the foo.dist-info but not foo folder.

Using setuptools and following the packaging python project I had to # out over 
70% of the example setup as they were all throwing warnings etc. and 
prohibiting the final build.  

Is there an alternative source to guide one through project packaging? Its now 
been two-days of struggle with no success.  

I would like to migrate some of my projects from R to Python.  But, honestly, 
packaging a python project seems far more difficult than building an R package. 
 I'm not trolling Python vs. R but my God, the level of frustration with python 
packaging is about to make me walk away.  

Either I am a complete moron or packaging python is a poorly documented 
nightmare.  If anyone can point me to source for pyhton packaging that is 
better than the Packaging Python Projects website I would greatly appreciate 
the direction.

Beyond Frustrated,
Glenn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] build does not include all .py modules

2018-08-23 Thread Glenn Schultz via Tutor

All,
followed links and suggestions and I have resolved most issues.  I continue to 
follow the python.org instructions as well.  The package builds and creates all 
the requsite files.  The challenge I am facing now is that the __init__.py does 
not include all the modules.  Below is a screen shot of the structure and 
result after the build.
The build and and lib files are fine as well.  Everything is there with no 
errors or warning.  When I run a test script I can import prepaymentmodeling 
but I get an error NameError name 'loandata' is not defined.  My __ini__.py 
successfully imported all package dependencies but did not import all the files 
it looks like this.

only traintest and loandata is remarked out.  The balance do not even show up.  
I searched the python site and SO but I am at a loss since it all looks good 
per the python.org instructions and links you guys sent me the other day.  Does 
anyone have an thoughts as to what is creating the problem?

S close it hurts,
Glenn

__ini__.py looks like this
all package imports are okay
.
from .traintest import *
#from loandata import *

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] building package on mac os

2018-09-09 Thread Glenn Schultz via Tutor

I have a package that I am working on.  I am using Pycharm.  The directories 
are set up correctly.  
In my frameworks I have
Python 2.7
Python 3.5
Python 3.6
Python 3.7
Current - which is Python 2.7

After navigating to the directory with the package I run the following in my 
terminal

python3 setup.py sdist bdist_wheel

This runs fine and it appears all is correct with no messages or warning.  Then 
I go to the main user directory
and pip install directory/packagename

It appears the wheel installs in a private/var/ folder

if I change the statement to python3.6 pip install  directory/packagename

I get an error 2 cannot find director.  I need to change my current python to 
3.6 and also figure out how to install the package.  I have seen some 
instructions to edit the bash file but before I do this I would like to resolve 
the install issue

Glenn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor