Python PIP has issues with path for MS Visual Studio 2010 Express for 64-bit install on Windows 7

Ultimately I was able to get pip running. In a nutshell (and redundant from info above) here is what I did to intall 64-bit packages for python 3.3: 1) Installed Microsoft Visual C++ 2010 Express Download Here (http://www.visualstudio.com/downloads/download-visual-studio-vs) 2) Installed Microsoft SDK 7.1 (Windows 7) (http://www.microsoft.com/en-us/download/details.aspx?id=8279) 3) Built/enabled the 64-bit tools in SDK. Go to … Read more

Multiple lookup_fields for django rest framework

Try this from django.db.models import Q import operator from functools import reduce from django.shortcuts import get_object_or_404 class MultipleFieldLookupMixin(object): def get_object(self): queryset = self.get_queryset() # Get the base queryset queryset = self.filter_queryset(queryset) # Apply any filter backends filter = {} for field in self.lookup_fields: filter[field] = self.kwargs[field] q = reduce(operator.or_, (Q(x) for x in filter.items())) return … Read more

How do I align text output in Python?

str.format already has the possibility to specify alignment. You can do that using {0:>5}; this would align parameter 0 to the right for 5 characters. We can then dynamically build a format string using the maximum number of digits necessary to display all numbers equally: >>> lower = [70, 79, 88, 97, 106, 115] >>> … Read more

Star * operator on left vs right side of an assignment statement

The difference between these two cases are explained when also taking into consideration the initial PEP for extended unpacking: PEP 3132 — Extended iterable unpacking. In the Abstract for that PEP we can see that: This PEP proposes a change to iterable unpacking syntax, allowing to specify a “catch-all” name which will be assigned a … Read more

Difference between df[x], df[[x]], df[‘x’] , df[[‘x’]] and df.x

df[x] — index a column using variable x. Returns pd.Series df[[x]] — index/slice a single-column DataFrame using variable x. Returns pd.DataFrame df[‘x’] — index a column named ‘x’. Returns pd.Series df[[‘x’]] — index/slice a single-column DataFrame having only one column named ‘x’. Returns pd.DataFrame df.x — dot accessor notation, equivalent to df[‘x’] (there are, however, … Read more

How to get flat clustering corresponding to color clusters in the dendrogram created by scipy

I think you’re on the right track. Let’s try this: import scipy import scipy.cluster.hierarchy as sch X = scipy.randn(100, 2) # 100 2-dimensional observations d = sch.distance.pdist(X) # vector of (100 choose 2) pairwise distances L = sch.linkage(d, method=’complete’) ind = sch.fcluster(L, 0.5*d.max(), ‘distance’) ind will give you cluster indices for each of the 100 … Read more

Embedding python in multithreaded C application

I had exactly the same problem and it is now solved by using PyEval_SaveThread() immediately after PyEval_InitThreads(), as you suggest above. However, my actual problem was that I used PyEval_InitThreads() after PyInitialise() which then caused PyGILState_Ensure() to block when called from different, subsequent native threads. In summary, this is what I do now: There is … Read more

how to understand closed and label arguments in pandas resample method?

Short answer: If you use closed=’left’ and loffset=”2T” then you’ll get what you expected: series.resample(‘3T’, label=”left”, closed=’left’, loffset=”2T”).sum() 2000-01-01 00:02:00 3 2000-01-01 00:05:00 12 2000-01-01 00:08:00 21 Long answer: (or why the results you got were correct, given the arguments you used) This may not be clear from the documentation, but open and closed in … Read more