DataFrame 的组成部分
为了更好地理解 DataFrame 对象,了解它由三个部分组成会很有帮助:
- values:一个二维 NumPy 数组,通过
.to_numpy()方法访问。 - columns:列名的索引,通过
.columns属性访问。 - index:行的索引,通过
.index属性访问。
通常,您可以把索引理解为由字符串或数字组成的列表,不过 pandas 的 Index 数据类型还支持更复杂的用法。(本课程后续会介绍。)
homelessness 已提供。
本练习是课程的一部分
使用 pandas 进行数据处理
练习说明
- 使用别名
pd导入pandas。 - 打印
homelessness中取值对应的二维 NumPy 数组。 - 打印
homelessness的列名。 - 打印
homelessness的索引。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import pandas using the alias pd
____
# Print the values of homelessness as a NumPy array
____
# Print the column index of homelessness
____
# Print the row index of homelessness
____