Friday, September 21, 2018

Changing dimensions of plot in matplotlib

To specify dimensions of a plot in matplotlib (e.g. to get longer x or y axis), do this:

fig = plt.figure(figsize=(20,3)) #x-axis = 20", y-axis=3"
ax = fig.add_subplot(111)
ax.plot(x, y)

[Courtesy: this]

Show summary statistics for a Pandas dataframe

To see the summary statistics for a Pandas dataframe, do this:

df.describe()

This will show things like: count, mean, standard deviation, etc.

To see column details (data types), do this:

df.info()


Cast a Pandas dataframe column to timestamp

To cast / convert a column in a Pandas dataframe to the timestamp datatype, do this:

df['timestamp'] = pd.to_datetime(df['timestamp'])


Jupyter-notebook: plot matplotlib graphs inline

To plot matplotlib graphs inline in Jupyter-notebook, do this:

import matplotlib.pyplot as plt
%matplotlib inline

Now, plt.plot(...) while show the graph inline.

Jupyter-notebook module reload

To reload modules being used in a jupyter-notebook (when they have been changed outside), do this:

%load_ext autoreload
%autoreload 2

This will automatically reload the module every time it is changed.

[Courtesy: this]

Tuesday, July 17, 2018

Restarting Nautilus on Ubuntu

Sometimes Nautilus does not work/open. One quick thing to try is to do killall nautilus in a terminal and then try to open it in the usual way. (Courtesy: this)

Monday, November 17, 2014

Passing lists in numba

If you plan to @jit() a Python function using numba, and one of the arguments is a list, it will be treated as an object, and the jit-ted function will probably be slower than the original. Instead, explicitly specify the argument data types (e.g. int32, double, unit64, etc.) within the @jit([data types]) declaration and, importantly, when calling the function, remember to convert the list into a numpy array of the data type specified in the jit declaration. For all your efforts, you should be rewarded with a good speed-up (if you have long-running loops).