# Create DataFramedata={'Name':['Alice','Bob','Charlie'],'Age':[24,27,22],'Score':[85,90,88]}df=pd.DataFrame(data,index=['A','B','C'])print(df)# Select the column with index 'Name'column_1=df['Name']print(column_1)row_1=df.loc['A']print(row_1)array=df.to_numpy()print(array)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Name Age Score
A Alice 24 85
B Bob 27 90
C Charlie 22 88
A Alice
B Bob
C Charlie
Name: Name, dtype: object
Name Alice
Age 24
Score 85
Name: A, dtype: object
[['Alice' 24 85]
['Bob' 27 90]
['Charlie' 22 88]]
The : Technique
: 表示所有
2: 表示从右往左取2个
:5 表示从左向右取5个
For example:
1
2
3
4
5
6
importnumpyasnpa=np.array([[1,2,3],[0,0,0],[2,3,4]])b=a[2:,:3]# Works only for numpy arrayprint(b)