Version 0.11.0 (April 22, 2013)
KeyError
A single label, e.g. 5 or 'a', (note that 5 is interpreted as a label of the index. This use is not an integer position along the index)
A list or array of labels ['a', 'b', 'c']
A slice object with labels 'a':'f', (note that contrary to usual python slices, both the start and the stop are included!)
A boolean array
.iloc is strictly integer position based (from 0 to length-1 of the axis), will raise IndexError when the requested indices are out of bounds. Allowed inputs are:
An integer e.g. 5
A list or array of integers [4, 3, 0]
A slice object with ints 1:7
A boolean array
See more at Selection by Position
.ix supports mixed integer and label based access. It is primarily label based, but will fallback to integer positional access. .ix is the most general and will support
any of the inputs to .loc and .iloc, as well as support for floating point label schemes. .ix is especially useful when dealing with mixed positional and label
based hierarchical indexes.
As using integer slices with .ix have different behavior depending on whether the slice
is interpreted as position based or label based, it’s usually better to be
explicit and use .iloc or .loc.
See more at Advanced Indexing and Advanced Hierarchical.
'D'
]
=
df3
[
'D'
]
.
astype
(
'float16'
)
df3
[
'E'
]
=
df3
[
'E'
]
.
astype
(
'int32'
)
df3
.
dtypes
Out[17]:
A float32
B float64
C float64
D float16
E int32
dtype: object
'20010105'
],
dtype
=
'O'
)
s
.
convert_objects
(
convert_dates
=
'coerce'
)
Out[20]:
0 2001-01-01
1 NaT
2 NaT
3 NaT
4 2001-01-04
5 2001-01-05
dtype: datetime64[ns]
dfi
.
dtypes
Out[27]:
A int32
B int32
C int32
D int64
E int32
dtype: object
casted
=
dfi
[
dfi
>
0
]
casted
Out[29]:
A B C D E
0 NaN NaN NaN 1 1
1 NaN NaN 1.0 1 1
2 NaN NaN 2.0 1 1
3 NaN NaN 3.0 1 1
4 1.0 NaN 4.0 1 1
5 NaN NaN 5.0 1 1
6 NaN NaN 6.0 1 1
7 NaN NaN 7.0 1 1
casted
.
dtypes
Out[30]:
A float64
B float64
C float64
D int64
E int32
dtype: object
df4
[
df4
>
0
]
casted
Out[35]:
A B C D E
0 NaN NaN NaN 1.0 1
1 NaN 0.567020 1.0 1.0 1
2 NaN 0.276232 2.0 1.0 1
3 NaN NaN 3.0 1.0 1
4 1.933792 NaN 4.0 1.0 1
5 NaN 0.113648 5.0 1.0 1
6 NaN NaN 6.0 1.0 1
7 NaN 0.524988 7.0 1.0 1
casted
.
dtypes
Out[36]:
A float32
B float64
C float64
D float16
E int32
dtype: object
s
[
1
]
=
np
.
nan
s
Out[22]:
0 2001-01-02
1 NaT
2 2001-01-02
dtype: datetime64[ns]
s
.
dtype
Out[23]:
dtype('<M8[ns]')
s
=
s
.
astype
(
'O'
)
s
Out[25]:
0 2001-01-02 00:00:00
1 NaT
2 2001-01-02 00:00:00
dtype: object
s
.
dtype
Out[26]:
dtype('O')
pd
.
read_hdf
(
'store.h5'
,
'table'
,
where
=
[
'index > 2'
])
Out[29]:
A B
3 3 3
4 4 4
(
len
(
idx
)),
index
=
idx
)
ts
[
'2001'
]
Out[32]:
2001-10-31 0.117967
2001-11-30 0.702184
2001-12-31 0.414034
Freq: M, dtype: float64
df
=
pd
.
DataFrame
({
'A'
:
ts
})
df
[
'2001'
]
Out[34]:
A
2001-10-31 0.117967
2001-11-30 0.702184
2001-12-31 0.414034
major_axis
=
pd
.
date_range
(
'20010102'
,
periods
=
4
),
minor_axis
=
[
'A'
,
'B'
,
'C'
,
'D'
])
p
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 4 (major_axis) x 4 (minor_axis)
Items axis: ItemA to ItemC
Major_axis axis: 2001-01-02 00:00:00 to 2001-01-05 00:00:00
Minor_axis axis: A to D
p
.
reindex
(
items
=
[
'ItemA'
])
.
squeeze
()
A B C D
2001-01-02 0.926089 -2.026458 0.501277 -0.204683
2001-01-03 -0.076524 1.081161 1.141361 0.479243
2001-01-04 0.641817 -0.185352 1.824568 0.809152
2001-01-05 0.575237 0.669934 1.398014 -0.399338
p
.
reindex
(
items
=
[
'ItemA'
],
minor
=
[
'B'
])
.
squeeze
()
2001-01-02 -2.026458
2001-01-03 1.081161
2001-01-04 -0.185352
2001-01-05 0.669934
Freq: D, Name: B, dtype: float64
Options.get_forward_data
near
above_below