Essential Basic Functionality
Here we discuss a lot of the essential functionality common to the pandas data structures. Here’s how to create some of the objects used in the examples from the previous section:
>>> import pandas as pd
>>> index = pd.date_range('1/1/2000', periods=8)
>>> s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
>>> df = pd.DataFrame(np.random.randn(8, 3), index=index,
>>> columns=['A', 'B', 'C'])
>>> wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
>>> major_axis=pd.date_range('1/1/2000', periods=5),
>>> minor_axis=['A', 'B', 'C', 'D'])
- 1 Head and Tail
- 2 Attributes and the raw ndarray(s)
- 3 Accelerated operations
- 4 Flexible binary operations
- 5 Descriptive statistics
- 6 Function application
- 7 Reindexing and altering labels
- 8 Iteration
- 9 .dt accessor
- 10 Vectorized string methods
- 11 Sorting
- 12 Copying
- 13 dtypes
- 14 Selecting columns based on
dtype
In [1]: index
Out[1]:
DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04',
'2000-01-05', '2000-01-06', '2000-01-07', '2000-01-08'],
dtype='datetime64[ns]', freq='D')
In [2]: df
Out[2]:
A B C
2000-01-01 0.112246 0.871721 -0.816064
2000-01-02 -0.784880 1.030659 0.187483
2000-01-03 -1.933946 0.377312 0.734122
2000-01-04 2.141616 -0.011225 0.048869
2000-01-05 -1.360687 -0.479010 -0.859661
2000-01-06 -0.231595 -0.527750 -1.296337
2000-01-07 0.150680 0.123836 0.571764
2000-01-08 1.555563 -0.823761 0.535420
In [3]: s
Out[3]:
a -1.032853
b 1.469725
c 1.304124
d 1.449735
e 0.203109
dtype: float64
In [4]: wp
Out[4]:
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 5 (major_axis) x 4 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2000-01-01 00:00:00 to 2000-01-05 00:00:00
Minor_axis axis: A to D