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

Write spark dataframe to file using python and ‘|’ delimiter

I have constructed a Spark dataframe from a query. What I wish to do is print the dataframe to a text file with all information delimited by ‘|’, like the following: +——-+—-+—-+—-+ |Summary|col1|col2|col3| +——-+—-+—-+—-+ |row1 |1 |14 |17 | |row2 |3 |12 |2343| +——-+—-+—-+—-+ How can I do this? Answer You can try to write … Read more

Why is episode done after 200 time steps (Gym environment MountainCar)?

When using the MountainCar-v0 environment from OpenAI-gym in Python the value done will be true after 200 time steps. Why is that? Because the goal state isn’t reached, the episode shouldn’t be done. import gym env = gym.make(‘MountainCar-v0’) env.reset() for _ in range(300): env.render() res = env.step(env.action_space.sample()) print(_) print(res[2]) I want to run the step … 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