Converting an RGB color tuple to a hexidecimal string
Use the format operator %: >>> ‘#%02x%02x%02x’ % (0, 128, 64) ‘#008040′ Note that it won’t check bounds… >>> ‘#%02x%02x%02x’ % (0, -1, 9999) ‘#00-1270f’
Use the format operator %: >>> ‘#%02x%02x%02x’ % (0, 128, 64) ‘#008040′ Note that it won’t check bounds… >>> ‘#%02x%02x%02x’ % (0, -1, 9999) ‘#00-1270f’
Using & operator, don’t forget to wrap the sub-statements with (): males = df[(df[Gender]==’Male’) & (df[Year]==2014)] To store your dataframes in a dict using a for loop: from collections import defaultdict dic={} for g in [‘male’, ‘female’]: dic[g]=defaultdict(dict) for y in [2013, 2014]: dic[g][y]=df[(df[Gender]==g) & (df[Year]==y)] #store the DataFrames to a dict of dict EDIT: … Read more
The problem could be that the Python libraries, per HTTP-Standard, first send an unauthenticated request, and then only if it’s answered with a 401 retry, are the correct credentials sent. If the Foursquare servers don’t do “totally standard authentication” then the libraries won’t work. Try using headers to do authentication: import urllib2, base64 request = … Read more
I figured that the DJANGO_SETTINGS_MODULE had to be set some way, so I looked at the documentation (link updated) and found: export DJANGO_SETTINGS_MODULE=mysite.settings Though that is not enough if you are running a server on heroku, you need to specify it there, too. Like this: heroku config:set DJANGO_SETTINGS_MODULE=mysite.settings –account <your account name> In my specific … Read more
There have been a handful of previous answers to similar questions (e.g. https://stackoverflow.com/a/22081678/325565), but they recommend a sub-optimal approach. Most of the previous answers recommend plotting a white polygon over a pcolormesh fill. This is less than ideal for two reasons: The background of the axes can’t be transparent, as there’s a filled polygon overlying … Read more
The long story short is that Flask does not provide any special capabilities to accomplish this. For simple one-off tasks, consider Python’s multithreading as shown below. For more complex configurations, use a task queue like RQ or Celery. Why? It’s important to understand the functions Flask provides and why they do not accomplish the intended … Read more
I finally found some time to do some experiments in order to understand the difference between them. Here’s what I discovered: log only allows positive values, and lets you choose how to handle negative ones (mask or clip). symlog means symmetrical log, and allows positive and negative values. symlog allows to set a range around … Read more
After opening up an issue with the SciPy team, we found that you need to upgrade pip with: pip install –upgrade pip And in Python 3 this works: python3 -m pip install –upgrade pip for SciPy to install properly. Why? Because: Older versions of pip have to be told to use wheels, IIRC with –use-wheel. … Read more
Python 3 renamed the unicode type to str, the old str type has been replaced by bytes. if isinstance(unicode_or_str, str): text = unicode_or_str decoded = False else: text = unicode_or_str.decode(encoding) decoded = True You may want to read the Python 3 porting HOWTO for more such details. There is also Lennart Regebro’s Porting to Python … Read more
This is a little faster (and looks nicer) np.argmax(aa>5) Since argmax will stop at the first True (“In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.”) and doesn’t save another list. In [2]: N = 10000 In [3]: aa = np.arange(-N,N) In [4]: timeit np.argmax(aa>N/2) 100000 … Read more