通过 DataFrame[ ]方式,取得得都是行, [ ] 中,添加过滤条件

data = pd.DataFrame(
np.arange(16).reshape(4,4),
index=['OP','CW','UZ','NM'],
columns=['one','two','three','four']
)
# print data
# one two three four
# OP 0 1 2 3
# CW 4 5 6 7
# UZ 8 9 10 11
# NM 12 13 14 15
# print data['one']
# <class 'pandas.core.series.Series'>
# x.shape (4,)
# OP 0
# CW 4
# UZ 8
# NM 12
# Name: one, dtype: int64
# print type(data[['one','two']])
# <class 'pandas.core.frame.DataFrame'>
# x.shape (4,2)
# one two
# OP 0 1
# CW 4 5
# UZ 8 9
# NM 12 13 # print data[:2]
# <class 'pandas.core.frame.DataFrame'>
# .shape (2,4)
# one two three four
# OP 0 1 2 3
# CW 4 5 6 7 # print data>5
# one two three four
# OP False False False False
# CW False False True True
# UZ True True True True
# NM True True True True # print data[data['three']>5] # x.shape (3,4)
# one two three four
# CW 4 5 6 7
# UZ 8 9 10 11
# NM 12 13 14 15 # print data[data>5]
# one two three four
# OP NaN NaN NaN NaN
# CW NaN NaN 6.0 7.0
# UZ 8.0 9.0 10.0 11.0
# NM 12.0 13.0 14.0 15.0 # data[data<5] = 0
# print data
# one two three four
# OP 0 0 0 0
# CW 0 5 6 7
# UZ 8 9 10 11
# NM 12 13 14 15 print data[2] # 报错。
print data.ix[2] # √
05-11 22:02