Pymongo $in Query Not Working

Seeing some strange behavior in Pymongo $in query. Looking for records that meet the following query: speciesCollection.find({“SPCOMNAME”:{“$in”:[‘paddlefish’,’lake sturgeon’]}}) The query returns no records. If I change it to find_one the it works returning the last value for Lake Sturgeon. The field is a text filed with one vaule. So I am looking for records that … Read more

Horizontal layout of patches in legend (matplotlib)

I create legend in my chart this way: legend_handles.append(matplotlib.patches.Patch(color=color1, label=’group1′)) legend_handles.append(matplotlib.patches.Patch(color=color2, label=’group2′)) ax.legend(loc=’upper center’, handles=legend_handles, fontsize=’small’) This results in the legend items stacked vertically (top-bottom), while I would like to put them horizontally left to right. How can I do that? (matplotlib v1.4.3) Answer There is an argument determining the number of columns ncol=. ax.legend(loc=’upper … Read more

Coreference resolution in python nltk using Stanford coreNLP

Stanford CoreNLP provides coreference resolution as mentioned here, also this thread, this, provides some insights about its implementation in Java. However, I am using python and NLTK and I am not sure how can I use Coreference resolution functionality of CoreNLP in my python code. I have been able to set up StanfordParser in NLTK, … Read more

Django Rest Framework – AssertionError Fix your URL conf, or set the `.lookup_field` attribute on the view correctly

I’m trying to return as single object (not a queryset) that is specific to a user without them having to specify an identifier/pk within the requested URL. Each user has an organisation FK. i.e. http://website/organisation and not http://website/organisation/1 I’m receiving the following error, since it’s expecting this identifier: AssertionError: Expected view OrganisationDetail to be called … Read more

How to view/decrypt Ansible vault credentials files from within a Python script?

I’m trying to figure out how to provide the following facilities to a Python script so that it can: Import Ansible Python modules Open up my defined ansible.cfg and read vault_password_file variable Read vault_password_file and temporarily store in a Python variable Decrypt a referenced Ansible vaulted file I found this code via google but it … Read more

Loading SKLearn cancer dataset into Pandas DataFrame

I’m trying to load a sklearn.dataset, and missing a column, according to the keys (target_names, target & DESCR). I have tried various methods to include the last column, but with errors. import numpy as np import pandas as pd from sklearn.datasets import load_breast_cancer cancer = load_breast_cancer() print cancer.keys() the keys are [‘target_names’, ‘data’, ‘target’, ‘DESCR’, … Read more