Class vs. Type in Python

Once upon a time, Python had both types and classes. Types were built-in objects defined in C; classes were what you built when using a class statement. The two were named differently because you couldn’t mix these; classes could not extend types. This difference was artificial, a limitation in the language implementation. Starting with Python … Read more

How to chunk a list in Python 3?

In Python 3’s itertools there is a function called zip_longest. It should do the same as izip_longest from Python 2. Why the change in name? You might also notice that itertools.izip is now gone in Python 3 – that’s because in Python 3, the zip built-in function now returns an iterator, whereas in Python 2 … Read more

How to get the index of ith item in pandas.Series or pandas.DataFrame

You could get it straight from the index s.index[5] Or s.index.values[5] It all depends on what you consider better. I can tell you that a numpy approach will probably be faster. For example. numpy.argsort returns an array where the first element in the array is the position in the array being sorted that should be … Read more