Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

The or and and python statements require truth-values. For pandas these are considered ambiguous so you should use “bitwise” | (or) or & (and) operations: These are overloaded for these kind of datastructures to yield the element-wise or (or and). Just to add some more explanation to this statement: The exception is thrown when you want to get the bool of a pandas.Series: What you hit was a place where the operator implicitly converted … Read more

How do I update Anaconda?

What 95% of people actually want In most cases what you want to do when you say that you want to update Anaconda is to execute the command: (But this should be preceeded by conda update -n base conda so you have the latest conda version installed) This will update all packages in the current environment to the latest version — … Read more

numpy max vs amax vs maximum

np.max is just an alias for np.amax. This function only works on a single input array and finds the value of maximum element in that entire array (returning a scalar). Alternatively, it takes an axis argument and will find the maximum value along an axis of the input array (returning a new array). The default behaviour of np.maximum is to take two arrays and compute … Read more

Relative imports in Python 3

It’s quite common to have a layout like this… …with a mymodule.py like this… …a myothermodule.py like this… …and a main.py like this… …which works fine when you run main.py or mypackage/mymodule.py, but fails with mypackage/myothermodule.py, due to the relative import… The way you’re supposed to run it is… …but it’s somewhat verbose, and doesn’t mix well with a shebang line like #!/usr/bin/env python3. The simplest … Read more

Curve curvature in numpy

EDIT: I put together this answer off and on over a couple of hours, so I missed your latest edits indicating that you only needed curvature. Hopefully, this answer will be helpful regardless. Other than doing some curve-fitting, our method of approximating derivatives is via finite differences. Thankfully, numpy has a gradient method that does these difference calculations for us, … Read more

How do I list all files of a directory?

os.listdir() will get you everything that’s in a directory – files and directories. If you want just files, you could either filter this down using os.path: or you could use os.walk() which will yield two lists for each directory it visits – splitting into files and dirs for you. If you only want the top directory you can break the first time it yields or, shorter:

How to send an email with Python?

I recommend that you use the standard packages email and smtplib together to send email. Please look at the following example (reproduced from the Python documentation). Notice that if you follow this approach, the “simple” task is indeed simple, and the more complex tasks (like attaching binary objects or sending plain/HTML multipart messages) are accomplished very rapidly. For sending email … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)