Numpy slicing image

I found a great cheat-sheet image that shows how Numpy slicing works: Thanks to scipy-lectures.org

AttributeError: ‘Series’ object has no attribute ‘strftime’

When getting this error, instead of dff[“New Time”] = dff[“Old Time”].strftime(“%d/%m/%Y %H:%M”) we should add “.dt” (it can be used to access the values of the series as datetimelike and return several properties.) dff[“New Time”] = dff[“Old Time”].dt.strftime(“%d/%m/%Y %H:%M”)

Example of Numba ‘for loop’ execution with “empty” numpy array population

This example is perfect for showing how fast Numba can be with when put right with Nopython mode (@jit(nopython=True) or@njit) import numpy as np import numba as nb from numba import jit, njit import time start_time = time.time() # @nb.jit(nb.float64[:](nb.float64[:])) @njit def f(arr): res = np.zeros(len(arr)) for i in range(len(arr)): res[i] = (arr[i]) ** 2 … Read more

Pandas convert date and time to float

In my case the .csv file had strings as date and time with the following format: 30/07/2017 21:01:17 I find this to be the simplest way to convert this column to float: df[‘dateTime’] = df[‘dateTime’].str.replace(‘/’, ”) df[‘dateTime’] = df[‘dateTime’].str.replace(‘:’, ”) df[‘dateTime’] = df[‘dateTime’].str.replace(‘ ‘, ”) df[‘dateTime’] = df[‘dateTime’].astype(float) So we are removing any signs and … Read more

How to run python script on multiple cores/threads (multiprocessing)

I’ve been looking for means of parallel execution in Python for quite a while. There’s a bunch of various libraries like Dask and Joblib Parallel. However using multiple threads won’t give you better performance due to the global interpreter lock called GIL. At the moment the best solution I’ve found is multiprocessing. It uses subprocesses … Read more

Calculate execution time in Python

In any Python script you can easily count execution time. In Jupiter notebooks simply use built-in magic commands like %%time in the very beginning of the cell. Now with the IDEs like PyCharm you should use something like this: import datetime as dt t1 = dt.datetime.now() # your code here t2 = dt.datetime.now() ft = … Read more

Fatal error C1083: Cannot open include file: ‘io.h’: No such file or directory

Cannot open include file 'io.h' No such file or directory error command failed with exit code 2

I’ve stumbled across this annoying error when trying to setup Cython working environment. Here are a couple of good guides: one, two. Everything went fine until I tried to compile the Cython code with python setup.py build_ext –inplace Then I got this nasty error: C:\Users\irmsc\anaconda3\envs\backtesting\include\pyconfig.h(59): fatal error C1083: Cannot open include file: ‘io.h’: No such … Read more