Retrieve from a Python Pandas series by position, rather than the index, with iloc:
Pass a list to .loc on a Python Pandas series, and get a series back:
The index in a Python Pandas series feels like a dict keys. But the keys can repeat:
To retrieve from a Python Pandas series, you can use [] to retrieve items. But don’t! In a series, [] uses the index. In a data frame, [] uses the column names. Confusing! Besides, .loc does everything [] does, but with more options and flexibility.
You can set a Python Pandas series index with set_axis. This returns a new series with the new index applied: s.index # still Index([‘a’, ‘b’, ‘c’], dtype=’str’)
Want to change the index of a Python Pandas series? Just assign to it:
By default, a Python Pandas series has a RangeIndex, like a string or list: Set an index like this:
Is a Python value of a particular type? It’s tempting to say: Far better to say: Why?– Works with subclasses– Second argument can be a tuple of possibilities
When should you use inheritance in Python? – An existing class mostly does what you want– Inheriting reduces your work — you only define differences– It’s an IS-A relationship, not just HAS-A– Otherwise: prefer composition. Remember: Inheritance is a tool, not a default.
What is a Python metaclass? – A subclass of type– Classes can be instances of a metaclass, rather than type– The metaclass’s __init__ sets attributes and methods Realistically, you should probably use a decorator instead of a metaclass. (But they’re fun to play with!)