Skip to content

Commit 07eb50b

Browse files
author
Mofan Zhou
committed
create pd12
1 parent ed924d3 commit 07eb50b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

numpy&pandas/12_selection.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# View more python tutorials on my Youtube and Youku channel!!!
2+
3+
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
4+
# Youku video tutorial: http://i.youku.com/pythontutorial
5+
6+
import pandas as pd
7+
import numpy as np
8+
9+
dates = pd.date_range('20130101', periods=6)
10+
df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=['A', 'B', 'C', 'D'])
11+
12+
print(df['A'], df.A)
13+
print(df[0:3], df['20130102':'20130104'])
14+
15+
# select by label: loc
16+
print(df.loc['20130102'])
17+
print(df.loc[:,['A','B']])
18+
print(df.loc['20130102', ['A','B']])
19+
20+
# select by position: iloc
21+
print(df.iloc[3])
22+
print(df.iloc[3, 1])
23+
print(df.iloc[3:5,0:2])
24+
print(df.iloc[[1,2,4],[0,2]])
25+
26+
# mixed selection: ix
27+
print(df.ix[:3, ['A', 'C']])
28+
# Boolean indexing
29+
print(df[df.A > 0])
30+
31+

0 commit comments

Comments
 (0)