《Python数据分析技术栈》第06章使用 Pandas 准备数据 06 访问DataFrame中的属性(Accessing attributes in a DataFrame)

06 访问DataFrame中的属性(Accessing attributes in a DataFrame)

《Python数据分析技术栈》第06章使用 Pandas 准备数据 06 访问DataFrame中的属性(Accessing attributes in a DataFrame)

In this section, we look at how to access the attributes in a DataFrame object.

本节将介绍如何访问 DataFrame 对象中的属性。

We use the following DataFrame:

我们使用以下 DataFrame:

combined_ages=pd.DataFrame({'class 1':[22,40],'class 2':[24,50],'class 3':[20,45]})

Attributes

The index attribute, when used with a DataFrame object, gives the type of an index object and its values.

索引属性与 DataFrame 对象一起使用时,可提供索引对象的类型及其值。

combined_ages.index

The columns attribute gives you information about the columns (their names and data type).

列属性可提供列的相关信息(名称和数据类型)。

combined_ages.columns

The index object and column object are both types of index objects. While the index object has a type RangeIndex, the columns object has a type “Index”. The values of the index object act as row labels, while those of the column object act as column labels.

索引对象和列对象都是索引对象的类型。索引对象的类型是 RangeIndex,而列对象的类型是 “索引”。索引对象的值作为行标签,而列对象的值作为列标签。

访问数据帧中的值 Accessing the values in the DataFrame

Using the values attribute, you can obtain the data stored in the DataFrame. The output, as you can see, is an array containing the values.

使用 values 属性,可以获取存储在 DataFrame 中的数据。如您所见,输出结果是一个包含值的数组。

combined_ages.values

你可能感兴趣的:(python,数据分析,Python数据分析技术栈,pandas,python,数据分析)