2. Advanced indexing - upalr/Python-camp GitHub Wiki
1 Index objects and labeled data
1.1 Pandas data structure
1.2 Creating a series
1.3 Creating a index
1.4 Examining an index
1.5 Modifying index nameindivi
1.6 Modifying index entries
Notice an exception is raised when attempting to assign to individual index entries or index slices. Index entries are immutable like dictionary keys. This restriction helps pandas optimize operation on series and dataframes.
It is technically possible to reassign to index by overriding it all at once. Notice that doing so also erases the name of the index.
1.7 Unemployment data
1.8 Assign the index
1.9 Removing extra column
1.10 Examining index & columns
1.11 read_csv() with index_col
1.12 Example : Building an index, then a DataFrame
You can also build the DataFrame and index independently, and then put them together. If you take this route, be careful, as any mistakes in generating the DataFrame or the index can cause the data and the index to be aligned incorrectly.
Building an index, then a DataFrame
2 Hierarchical indexing
2.1 Stock data
2.2 Setting index
2.3 MultiIndex on DataFrame
2.4 Sorting index
Info: With a MultiIndex, you should always ensure the index is sorted. You can skip this only if you know the data is already sorted on the index fields.
2.5 Indexing (Individual row)
2.6 Slicing (outermost index)
2.7 Fancy-indexing(outermost-index)
2.8 Fancy-indexing(innermost-index)
2.9 Slicing (both indexes)
There is a trick to slicing with hierarchical indexes. The tuple use for the index doesn't recognize slicing with colons (:) naively. To force that to work we need to use the python built in slice
explicitly. Foe example: