dataframe.iloc.values
时间: 2023-09-24 13:13:46 浏览: 50
The attribute `values` in the `iloc` property of a Pandas DataFrame returns a NumPy array representation of the DataFrame's values.
For example, suppose we have a DataFrame `df`:
```
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
```
We can access the values of the DataFrame using the `iloc` property:
```
values = df.iloc.values
```
This will return a NumPy array of the same shape as the DataFrame:
```
array([[1, 4, 7],
[2, 5, 8],
[3, 6, 9]])
```
Note that the `values` attribute returns a copy of the data, not a view. Therefore, any modifications made to the NumPy array will not affect the original DataFrame.
相关问题
df.iloc.values用法
df.iloc.values是一个属性,可以用于获取DataFrame中的所有数据(不包括行标签和列标签),返回一个二维数组。它的使用方法如下:
``` python
values = df.iloc.values
```
其中,df是一个DataFrame对象,values是一个二维数组,可以使用NumPy的数组操作对其进行处理。例如,可以使用np.sum(values)计算所有数据的总和,或者使用np.mean(values, axis=0)计算每一列的平均值。
df.iloc[].values使用方法
`df.iloc[]`是用于通过行索引和列索引来获取DataFrame中的特定元素或切片的方法。在`[]`内部,可以使用整数、整数切片、布尔数组或布尔条件来选择所需的行或列。
以下是一些使用`df.iloc[].values`的示例:
1. 获取特定行的值:
```python
row_values = df.iloc[2].values
```
这将返回DataFrame中第3行的所有值作为一个数组。
2. 获取特定列的值:
```python
column_values = df.iloc[:, 1].values
```
这将返回DataFrame中第2列的所有值作为一个数组。
3. 获取特定行和列的值:
```python
values = df.iloc[2:5, 1:3].values
```
这将返回DataFrame中第3至第5行、第2至第3列的值作为一个二维数组。
请注意,`df.iloc[].values`返回的是一个NumPy数组。如果要以DataFrame形式返回结果,可以使用`df.iloc[]`替代`df.iloc[].values`。