.. currentmodule:: pandas
.. ipython:: python :suppress: import numpy as np import random import os np.random.seed(123456) from pandas import * import pandas as pd randn = np.random.randn randint = np.random.randint np.set_printoptions(precision=4, suppress=True)
This is a respository for short and sweet examples and links for useful pandas recipes. We encourage users to add to this documentation.
This is a great First Pull Request (to add interesting links and/or put short code inline for existing links)
The :ref:`indexing <indexing>` docs.
Using loc and iloc in selections
Extending a panel along the minor axis
The :ref:`multindexing <indexing.hierarchical>` docs.
Creating a multi-index from a labeled frame
Slicing a multi-index with xs #2
Partial Selection, the need for sortedness
Prepending a level to a multiindex
The :ref:`grouping <groupby>` docs.
Apply to different items in a group
Replacing values with groupby means
Sort by group with aggregation
Create multiple aggregated columns
Rolling Computation window based on values instead of counts
The :ref:`Pivot <reshaping.pivot>` docs.
Frequency table like plyr in R
The :ref:`Resample <timeseries.resampling>` docs.
TimeGrouping of values grouped across time
Resampling with custom periods
Resample intraday frame without adding new days
The :ref:`Concat <merging.concatenation>` docs. The :ref:`Join <merging.join>` docs.
Join with a criteria based on the values
The :ref:`Plotting <visualization>` docs.
Setting x-axis major and minor labels
The :ref:`CSV <io.read_csv_table>` docs
Reading the first few lines of a frame
The :ref:`SQL <io.sql>` docs
Reading from databases with SQL
The :ref:`Excel <io.excel>` docs
Reading from a filelike handle
The :ref:`HDFStores <io.hdf5>` docs
Simple Queries with a Timestamp Index
Managing heteregenous data using a linked multiple table hierarchy
Merging on-disk tables with millions of rows
Troubleshoot HDFStore exceptions
Storing Attributes to a group node
.. ipython:: python df = DataFrame(np.random.randn(8,3)) store = HDFStore('test.h5') store.put('df',df) # you can store an arbitrary python object via pickle store.get_storer('df').attrs.my_attribute = dict(A = 10) store.get_storer('df').attrs.my_attribute
.. ipython:: python :suppress: store.close() os.remove('test.h5')
The :ref:`Timedeltas <timeseries.timedeltas>` docs.
Create timedeltas with date differences
To globally provide aliases for axis names, one can define these 2 functions:
.. ipython:: python def set_axis_alias(cls, axis, alias): if axis not in cls._AXIS_NUMBERS: raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias)) cls._AXIS_ALIASES[alias] = axis def clear_axis_alias(cls, axis, alias): if axis not in cls._AXIS_NUMBERS: raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias)) cls._AXIS_ALIASES.pop(alias,None) set_axis_alias(DataFrame,'columns', 'myaxis2') df2 = DataFrame(randn(3,2),columns=['c1','c2'],index=['i1','i2','i3']) df2.sum(axis='myaxis2') clear_axis_alias(DataFrame,'columns', 'myaxis2')