Skip to content

Latest commit

 

History

History
293 lines (191 loc) · 8.39 KB

cookbook.rst

File metadata and controls

293 lines (191 loc) · 8.39 KB
.. 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)

Cookbook

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)

Selection

The :ref:`indexing <indexing>` docs.

Boolean Rows Indexing

Using loc and iloc in selections

Extending a panel along the minor axis

Boolean masking in a panel

Selecting via the complement

MultiIndexing

The :ref:`multindexing <indexing.hierarchical>` docs.

Creating a multi-index from a labeled frame

Slicing

Slicing a multi-index with xs

Slicing a multi-index with xs #2

Sorting

Multi-index sorting

Partial Selection, the need for sortedness

Levels

Prepending a level to a multiindex

Flatten Hierarchical columns

Grouping

The :ref:`grouping <groupby>` docs.

Basic grouping with apply

Using get_group

Apply to different items in a group

Expanding Apply

Replacing values with groupby means

Sort by group with aggregation

Create multiple aggregated columns

Expanding Data

Alignment and to-date

Rolling Computation window based on values instead of counts

Splitting

Splitting a frame

Pivot

Partial sums and subtotals

Timeseries

Between times

Vectorized Lookup

Resampling

The :ref:`Resample <timeseries.resampling>` docs.

TimeGrouping of values grouped across time

TimeGrouping #2

Resampling with custom periods

Resample intraday frame without adding new days

Resample minute data

Merge

The :ref:`Concat <merging.concatenation>` docs. The :ref:`Join <merging.join>` docs.

emulate R rbind

Self Join

How to set the index and join

KDB like asof join

Join with a criteria based on the values

Plotting

The :ref:`Plotting <visualization>` docs.

Make Matplotlib look like R

Setting x-axis major and minor labels

Data In/Out

CSV

The :ref:`CSV <io.read_csv_table>` docs

read_csv in action

Reading a csv chunk-by-chunk

Reading the first few lines of a frame

Inferring dtypes from a file

Dealing with bad lines

SQL

The :ref:`SQL <io.sql>` docs

Reading from databases with SQL

Excel

The :ref:`Excel <io.excel>` docs

Reading from a filelike handle

HDFStore

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

Large Data work flows

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')

Miscellaneous

The :ref:`Timedeltas <timeseries.timedeltas>` docs.

Operating with timedeltas