luc*_*uca 3 python numpy pandas
我有两只熊猫.系列......
import pandas as pd
import numpy as np
length = 5
s1 = pd.Series( [1]*length ) # [1, 1, 1, 1, 1]
s2 = pd.Series( [2]*length ) # [2, 2, 2, 2, 2]
Run Code Online (Sandbox Code Playgroud)
...我希望将它们连接在一起,使用前两个系列中的交错值.类似的东西:[1,2,1,2,1,2,1,2,1,2]
In[27]:pd.Series(np.column_stack((s1,s2)).flatten())
Out[27]:
0 1
1 2
2 1
3 2
4 1
5 2
6 1
7 2
8 1
9 2
dtype: int64
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
170 次 |
| 最近记录: |