I’m trying to run fillna on a column of type datetime64[ns]. When I run something like: df[‘date’].fillna(datetime(“2000-01-01”)) I get: TypeError: an integer is required Any way around this? Answer This should work in 0.12 and 0.13 (just released). @DSM points out that datetimes…
Tag: python
Format / Suppress Scientific Notation from Pandas Aggregation Results
How can one modify the format for the output from a groupby operation in pandas that produces scientific notation for very large numbers? I know how to do string formatting in python but I’m at a loss when it comes to applying it here. This suppresses the scientific notation if I convert to string but n…
Specify specific testcases in Python unit test TestLoader
I have the following folder structure. Both the test files have two test cases each. File smoke.py contains The above code runs four test cases which is expected. Is there a way to run some specific test cases from file test1.py and test2.py where I can explicitly add those testcases to the suite1 and suite 2…
Fast arbitrary distribution random sampling (inverse transform sampling)
The random module (http://docs.python.org/2/library/random.html) has several fixed functions to randomly sample from. For example random.gauss will sample random point from a normal distribution with a given mean and sigma values. I’m looking for a way to extract a number N of random samples between a g…
What is a ‘NoneType’ object?
I’m getting this error when I run my python script: I’m pretty sure the ‘str’ means string, but I dont know what a ‘NoneType’ object is. My script craps out on the second line, I know the first one works because the commands from that line are in my asa as I would expect. A…
How to use psutil.get_cpu_percent()?
How to exactly use the function get_cpu_percent()? My code is: Here I am calling a Function called SDKTestSuite.DijSDK_CalculateFps() and I am calling get_cpu_percent() to get the CPU usage of this call. I am Calling this function for different inputs, The result is sometimes the CPU usage gives 0.0% which is…
How to find pg_config path
Complete newbie here, trying to set up Django to work with PostgreSQL. I’m using mac osx 10.6.8. I have also installed PostgreSQL 9.3 When I run pip install psycopg2 in terminal I get the following error I’ve seen a number of posts on this how-to-install-psycopg2-with-pip-on-python pg-config-execu…
What’s the advantage of a trailing underscore in Python naming?
I am used to naming Python arguments in this way: what’s the advantage if I do this instead: as is recommended by PEP008? There must be a good reason for the trailing underscore, so what is it? Answer Exactly what it gives in the PEP: it allows you to use something that would otherwise be a Python keywo…
Python- Saving/Accessing file extension icons and using them in a Tkinter program
I’m currently trying to figure out how to create some code which will take the input of a file extension like ‘.png’ and return the icon associated with that filetype on the system. I’m using python 2.7.6 and using Windows 8. I’ve been looking for code for this for hours to thing…
Building ‘limitless’ menu trees with Django
I have a model: And want to build a template which contains menu with limitless parent-child relations for each entry, where parent id’s of the “first-level” elements is 0. And as a result to build any html menu trees I want. Answer Don’t re-invent the wheel; use a dedicated Django ext…