【发布时间】:2021-10-29 23:37:23
【问题描述】:
如何将 numpy 数组转换为 pandas 数据框。 为简单起见,该数组仅包含 5 个值。实际上还有更多。
import numpy as np
import pandas as pd
nparray1 = np.array([1,2,3,4,5])
nparray2 = np.array([2,2,2,6,6])
我想从 nparray1 中得到以下数据帧结构:
| column1 | column2 | column3 | column4 | column5 |
|---------|---------|---------|---------|---------|
| 1 | 2 | 3 | 4 | 5 |
| | | | | |
在下一步中,我想将 nparray2 附加到数据框:
| column1 | column2 | column3 | column4 | column5 |
|---------|---------|---------|---------|---------|
| 1 | 2 | 3 | 4 | 5 |
| 2 | 2 | 2 | 6 | 6 |
【问题讨论】:
标签: python arrays pandas dataframe numpy