x =pd.Series(np.arange(0,10))
y =pd.Series(np.arange(100,110))
df =pd.DataFrame({ 'x':x, 'y':y})
df
x y
0 0 100
1 1 101
2 2 102
3 3 103
4 4 104
5 5 105
6 6 106
7 7 107
8 8 108
9 9 109
运算 |
变量[] |
变量.loc[] !!! 包含末尾 !!! |
df.loc[] !!! 包含末尾 !!! |
df[] |
取整列 |
df.x 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 |
|
df.loc[:,'x'] 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 |
df['x'] 0 01 12 23 34 45 56 67 78 89 9 |
取整行 |
|
|
df.loc[2:5] x y 2 2 102 |

本文介绍了如何使用pandas对数据框进行切片操作,通过示例展示了如何创建Series和DataFrame,并对其中的'x'和'y'列进行切片和赋值。展示了如何通过索引访问和修改数据,例如访问第0到4行以及对选定列进行数值更新。
最低0.47元/天 解锁文章
1226

被折叠的 条评论
为什么被折叠?



