dataframe转换成array并生成代码python
时间: 2024-01-06 19:05:02 浏览: 71
python中numpy 的array矩阵,列表与pandas中的dataframe互相转换
Sure, here is some sample code in Python to convert a Pandas DataFrame to a NumPy array:
```python
import pandas as pd
import numpy as np
# Create a sample DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
# Convert DataFrame to NumPy array
array = np.array(df)
# Print the resulting array
print(array)
```
This code will create a 3x3 array from the DataFrame with columns A, B, and C. You can use this same approach for any DataFrame with any number of columns and rows.
Let me know if you have any other questions!
阅读全文