AttributeError: 'DataFrame' object has no attribute 'flatten'
时间: 2023-09-20 17:11:17 浏览: 314
Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决
5星 · 资源好评率100%
`flatten()` is a method for flattening arrays in Python. It does not work on Pandas DataFrame objects. If you are trying to convert a DataFrame to a flattened array, you can use the `values` attribute to get the underlying Numpy array and then flatten that. For example:
```
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
arr = df.values.flatten()
print(arr)
```
This will output:
```
[1 4 2 5 3 6]
```
If you are trying to do something else, please provide more context or code for me to help you better.
阅读全文