9月27日总结
属性与底层数据
Pandas 可以通过多个属性访问元数据:
-
shape:
- 输出对象的轴维度,与 ndarray 一致
-
轴标签
- Series: Index (仅有此轴)
- DataFrame: Index (行) 与列
注意: 为属性赋值是安全的!
In [7]: df[:2]
Out[7]:
A B C
2000-01-01 -0.173215 0.119209 -1.044236
2000-01-02 -0.861849 -2.104569 -0.494929
In [8]: df.columns = [x.lower() for x in df.columns]
In [9]: df
Out[9]:
a b c
2000-01-01 -0.173215 0.119209 -1.044236
2000-01-02 -0.861849 -2.104569 -0.494929
2000-01-03 1.071804 0.721555 -0.706771
2000-01-04 -1.039575 0.271860 -0.424972
2000-01-05 0.567020 0.276232 -1.087401
2000-01-06 -0.673690 0.113648 -1.478427
2000-01-07 0.524988 0.404705 0.577046
2000-01-08 -1.715002 -1.039268 -0.370647
Pandas 对象(Index (opens new window), Series (opens new window), DataFrame (opens new window))相当于数组的容器,用于存储数据、执行计算。大部分类型的底层数组都是 numpy.ndarray (opens new window)。不过,Pandas 与第三方支持库一般都会扩展 NumPy 类型系统,添加自定义数组(见数据类型 (opens new window))。

浙公网安备 33010602011771号