我有两个 pandas.Series...
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]
...我想让它们与前 2 个系列中的交错值一起加入一个系列中。 类似于:[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
最佳答案
使用 np.column_stack :
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
关于python - 如何将两个 Pandas 系列加入一个具有交错值的系列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39293328/