Lists as default arguments?

I recently stumbled upon something weird (well at least I perceive it that way): In [1]: class A(object): ...: def __init__(self, name, l=[]): ...: = name ...: self.l = l ...: In [2]: a = A("a") I...
more »

2017-05-20 23:05 (0) Answers

Python - Accesing a list from another class method

I have a little problem with two different classes and two methods from the same class. I have a class B which is using both methods from class a which seems to work fine. The problem however is that the first method from class a (insert) changes a ...
more »

2017-05-20 12:05 (1) Answers

Why is int type error? TypeError

I got an error, TypeError: slice indices must be integers or None or have an index method . Traceback is like Traceback (most recent call last): File "", line 24, in <module> wavdata = wav[z:q] TypeError: slice indices must be int...
more »

2017-05-20 09:05 (3) Answers

Calling functions in functions - Python

How would I go about to get this to work? I've searched but I can't get it to work still. Should I just put the a() function in the b function even if I add more variables? counter = 1 def a(): az = 1 bz = 2 cz = 3 def b(): a() ...
more »

2017-05-20 04:05 (2) Answers

In django, how generic view works

I have started learning django, I'm not sure how generic view works. I read django documentation several times, I can't gain clear understanding of how generic view works. Very strange but it works well. It retrieves data from the database and render...
more »

2017-05-20 00:05 (2) Answers

TypeError: unhashable type: 'slice'

I am trying to run a regression using the following dataframe dfMyRoll the head of the dataframe looks like: SCORE SCORE_LAG date 2007-10-29 -0.031551 NaN 2007-10-30 0.000100 -0.031551 2007-10-31 ...
more »

2017-05-19 23:05 (1) Answers

robust numpy.float64 equality testing

Is there a robust way to test for equality of floating point numbers, or to generally ensure that floats that should be equal actually do equal each other to within the float's precision? For example, here is a distressing situation: >> np.mod...
more »

2017-05-19 21:05 (2) Answers

How to lock down pandas dataframe structure

Simply put, what are the preferred practices for writing larger python applications that use pandas dataframes as its primary method for data representation? I often find myself struggling to maintain inconsistencies in dataframes, sometimes invaria...
more »

2017-05-19 15:05 (0) Answers

Python's fsolve not working

I'm currently trying to find the intercept of 2 equations from my code (pasted below). I'm using fsolve and have used it successfully in one part but I can't get it to work for the second. Confusingly it's not showing up an error, if you paste this...
more »

2017-05-19 11:05 (1) Answers

ANOVA for groups within a dataframe using scipy

I have a dataframe as follows. I need to do ANOVA on this between three conditions. The dataframe looks like: data0 = pd.DataFrame({'Names': ['CTA15', 'CTA15', 'AC007', 'AC007', 'AC007','AC007'], 'value': [22, 22, 2, 2, 2,5], 'condition':[...
more »

2017-05-19 10:05 (1) Answers