How is a Pandas crosstab different from a Pandas pivot_table?

The main difference between the two is the pivot_table expects your input data to already be a DataFrame; you pass a DataFrame to pivot_table and specify the index/columns/values by passing the column names as strings. With cross_tab, you don’t necessarily need to have a DataFrame going in, as you just pass array-like objects for index/columns/values. … Read more

Is the order of a Python dictionary guaranteed over iterations?

Yes, the same order is guaranteed if it is not modified. See the docs here. Edit: Regarding if changing the value (but not adding/removing a key) will affect the order, this is what the comments in the C-source says: /* CAUTION: PyDict_SetItem() must guarantee that it won’t resize the * dictionary if it’s merely replacing … Read more

Compute a confidence interval from sample data assuming unknown distribution

If you don’t know the underlying distribution, then my first thought would be to use bootstrapping: https://en.wikipedia.org/wiki/Bootstrapping_(statistics) In pseudo-code, assuming x is a numpy array containing your data: import numpy as np N = 10000 mean_estimates = [] for _ in range(N): re_sample_idx = np.random.randint(0, len(x), x.shape) mean_estimates.append(np.mean(x[re_sample_idx])) mean_estimates is now a list of 10000 … Read more

How to pass additional parameters to numba cfunc passed as LowLevelCallable to scipy.integrate.quad

1. Passing extra arguments through scipy.integrate.quad The quad docs say: If the user desires improved integration performance, then f may be a scipy.LowLevelCallable with one of the signatures: double func(double x) double func(double x, void *user_data) double func(int n, double *xx) double func(int n, double *xx, void *user_data) The user_data is the data contained in … Read more

new pythonic style for shared axes square subplots in matplotlib?

Just use adjustable=”box-forced” instead of adjustable=”box”. As @cronos mentions, you can pass it in using the subplot_kw kwarg (additional keyword arguments to subplots are passed on to the Figure not the Axes, thus the need for subplot_kw). Instead, I’m going to use setp, which basically just does for item in sequence: item.set(**kwargs). (All matplotlib artists … Read more